Huawei Ads Kit — Banner Ads

Ibrahim R. Serpici
Huawei Developers
Published in
3 min readAug 27, 2020

In this article, I will try to explain how you can easily implement Huawei Banner Ads to your project and monetize your application right away!

What is Banner Ad

Banner ads are rectangular images that can be placed to the top, middle, or bottom of your app’s screen. Banner ads refresh automatically at regular intervals. When a user taps a banner ad, the user is redirected to the advertiser’s page in most cases.

To implement banner ads, you need to implement Huawei Ads Kit dependency to your project which I explained below.

How to Implement Ads Kit

Things you need to have

1) A Huawei Developer Account (It needs to be Enterprise Level account for monetization)

2) A Huawei phone with HMS 4.0.0.300 or later

3) A computer with Android Studio , Jdk 1.8, SDK platform 26 and Gradle 4.6 installed.

Things Need To Be Done Before Implementation

First things first HMS Core needs to be implemented to the your project. To see how to implement HMS Core please refer this link.

After HMS Core implementation, Ads Kit dependency needs to be added in app levelbuild.gradle” file

4) Configure obfuscation scripts to prevent HUAWEI Ads kit from being obfuscated. Add the following two lines of code to the app/proguard-rules.pro

After Completing the steps above. All you need to do is initialize Huwei Ads by calling HwAds.init() method in your application. Then the application is ready to implement all kind of various ad types which I will show below.

Implementing Banner Ads

To implement Banner Ad, BannerView object needs to be initialized either with XML or directly in code.

Adding Banner Ads Through XML

Create BannerView in your XML

Call it from your class & load the add.

Run the application and the result will be like below.

Adding Banner Ads Programmatically Without XML

Lets create another Banner ad at the bottom of our view without using XML. All you need to do is creating & initializing banner ad , adding it to the specific layout, then loading the ad as below.

As shown above, we have successfully added second banner ad to our program without touching the xml.

Optional: Adding Ad Listener

After implementing banner ads to your project, if you want to proceed further, you can add Ad listener to listen ad events like is AdLoaded is AdFailed is AdClicked etc.

As you can see, it is really easy to implement banner ads to your android application with Huawei Ads Kit. Stay tuned for other ad types. You can find the github project below.

Resources

--

--