In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains the "methods and steps of adding Banner ads". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the methods and steps of adding Banner advertisements".
What is Banner advertisement?
Banner ads are rectangular images that occupy a place at the top, middle, or bottom of the application. The content of the ad is automatically refreshed at regular intervals, and when you click on the content, it jumps to the advertiser's page. The advantage of Banner advertising lies in its long-term stable display and large exposure. Suitable for game pages, reading information pages, tool function pages and other pages where users stay for a long time or visit frequently.
Banner advertising is the most commonly used mobile advertising, if you are just exposed to mobile advertising, you might as well start with Banner advertising, the following article will explain the development steps in detail.
The sample code has been opened up in relevant communities. Developers are welcome to follow, download and provide valuable comments:
Official address of Githubo: https://github.com/hms-core/hms-ads-demo-java
Official address of Gite: https://gitee.com/hms-core/hms-ads-demo-java
prerequisite
HUAWEI Ads SDK relies on HMS Core (APK) 4.0.0.300 or above. If HMS Core (APK) 4.0.0.300 or above is not installed on the device, the relevant interface of HUAWEI Ads SDK cannot be used.
Before developing the application, you need to register as a developer on the Huawei developer Alliance website and complete the real name verification. For more information, please see account Registration and Verification.
See create a project and add an application to the project to complete the creation of the application.
Pre-development preparation
The integration of advertising services requires the following four key steps. Please refer to the Huawei developer Alliance documentation.
1. Import HUAWEI Ads SDK
two。 Configure network permissions
3. Configuration obfuscation script
4. Initialize SDK
Key steps in development
1.1 add BannerView.
HUAWEI Ads SDK supports the following two ways to add BannerView to display Banner ads:
Add by configuring the XML layout file
Add BannerView to the XML layout file and set the ad space ID and size by configuring the hwads:adId and hwads:bannerSize properties. The following sample code shows how to add BannerView to the XML layout file.
The following sample code shows how to get BannerView
BannerView bannerView = findViewById (R.id.hw_banner_view)
Add it programmatically.
Add BannerView to the code and set the ad space ID and size
BannerView bannerView = new BannerView (this); / / "testw6vs28auh4" needs to be changed to formal ad space ID bannerView.setAdId ("testw6vs28auh4"); bannerView.setBannerAdSize (BannerAdSize.BANNER_SIZE_360_57); FrameLayout adFrameLayout = findViewById (R.id.ad_frame); adFrameLayout.addView (bannerView) when it is officially released.
1.2 get ads
After the BannerView is created, the advertisement is obtained through the loadAd () method of the BannerView class.
Import com.huawei.hms.ads.AdParam; import com.huawei.hms.ads.BannerAdSize; import com.huawei.hms.ads.banner.BannerView; public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); / / get BannerView BannerView bannerView = findViewById (R.id.hw_banner_view) / / set ad space ID and ad size. "testw6vs28auh4" is the test-specific ad bit ID bannerView.setAdId ("testw6vs28auh4"); bannerView.setBannerAdSize (BannerAdSize.BANNER_SIZE_360_57); / / set the rotation interval to 30 seconds bannerView.setBannerRefresh (30); / / create an ad request to get the ad AdParam adParam = new AdParam.Builder (). Build () BannerView.loadAd (adParam);}}
1.3 monitor advertising events
Listen for advertising events by implementing methods in the AdListener class. For detailed methods, see the AdListener class in the API documentation.
BannerView.setAdListener (adListener) Private AdListener adListener = new AdListener () {@ Override public void onAdLoaded () {/ / call.} @ Override public void onAdFailed (int errorCode) {/ / when ad acquisition fails.} @ Override public void onAdOpened () {/ / Call...} @ Override public void onAdClicked () {/ / call when the ad clicks.} @ Override public void onAdLeave () {/ / call when the ad leaves the application.} @ Override public void onAdClosed () { / / called when the advertisement is turned off.}} Thank you for your reading, the above is the content of "the methods and steps of adding Banner advertising". After the study of this article, I believe you have a deeper understanding of the methods and steps of adding Banner advertising, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.