How to use Huawei Ads with AdMob mediation (Native Android)
In this article, we will talk about showing Huawei ads with Admob SDK through mediation. Supported ad types are :
Banner, interstitial, rewarded, and native ads.
For cross-platform integrations please check the following medium links :
What is ad meditation?
Ad Mediation gives multiple ad networks access to your ad inventory, and gets them to compete against each other for ad slots. This process increases competition among advertisers and in return, increases your ad revenue. The mediation platform checks what CPM all the various ad networks are offering and looks for the highest one.
Preparations Before Coding
1-) Initialize AdMob Mobile Ads SDK
Follow this link to integrate AdMob SDK into your android application. This step also includes creating a Google Admob account and registration of your application.
New AdMob Review Policy
AdMob changed its review policy in February 2021. Check this link for the details. This policy applies to the new applications, but before use Huawei mediation adapter contact AdMob support. With this change, Admob can limit your ad serving limit if your application is not linked to a supported app store. (currently, AppGallery is not a supported store)
This new policy can affect your monetization if your application is listed in AppGallery. I recommend you to contact AdMob support about the details and effects of this restriction.
2-) Configure a custom event on AdMob
Follow the steps in this medium link. After the mediation steps on AdMob console are completed, note your ad unit id(s) to use later in your application.
Note: For this step, ad unit creation is needed from Huawei Ads console, check this link to create an ad unit. After that add your Huawei ad unit id as a parameter.
3-) Integrate The Huawei Mediation Adapter
In your project-level build.gradle, include Huawei’s Maven repository.
repositories {
google()
jcenter() // Also, make sure jcenter() is included
maven { url 'https://developer.huawei.com/repo/' }
maven {url "https://jitpack.io"}
}
...
allprojects {
repositories {
google()
jcenter() // Also, make sure jcenter() is included
maven { url 'https://developer.huawei.com/repo/' }
maven {url "https://jitpack.io"}
}
}
In the app-level build.gradle, include Huawei Ads dependency (required by the adapter) and the adapter.
dependencies {
implementation 'com.huawei.hms:ads:3.4.49.301'
implementation
'com.github.Explore-In-HMS:huawei.admob_mediation:<latest_version>'
}
if your app can run only on Huawei mobile phones, you can integrate the Huawei Ads Lite SDK (optional)
dependencies {
implementation 'com.huawei.hms:ads-lite:13.4.49.301'
implementation
'com.github.Explore-In-HMS:huawei.admob_mediation:<latest_version>'
}
Check this GitHub page for more details and any updates.
Demo Application - Banner Ad
Let's start with our layout…
This is our banner ad layout. Add this piece of code to your layout. Optionally, you can change the ad size to “LARGE_BANNER” or “MEDIUM_RECTANGLE”. Finally, enter your ad unit id and we are done :)
After the layout is done, create a Kotlin class and add the following code :
This is the code for the banner ad. You don’t need to use all the methods for the ad listener, as you can see I just filled “onAdFailedToLoad” method. You can use the ad listener methods according to your needs.
Lifecycle methods are really important to avoid memory leaks and unnecessary ad requests.
Other Ad Types
For Interstitial ads follow this AdMob guide.
For Rewarded ads follow this AdMob guide.
For Native ads take this Github project as a reference. For the Java version click here.
After the steps are completed, you only need to change your ad unit id and the adapter will do the rest.