In this documentation we explained how to use Huawei-Ima Adapter in native android.
- Sign in to Huawei Developer Console and create an ad unit for Roll Ads.
Interactive Media Ads is a suite of SDKs that make it easy to integrate multimedia ads into your apps. IMA SDKs can request ads from any Vast-compliant ad server and manage ad playback in your apps.
Developers need to create ad tags to show video ads in their application. These ad tags are unique URLs that generated by publishers from Ad Manager.
- Sign in to Google Ad Manager.
- Click Inventory and then Ad units.
- Locate and click your video ad unit.
- Click Generate tags.
- Complete the 3-step process and click Continue after each step (Tag type, Tag Options, and Tag Results)
- Click done.
A VAST ad tag URL is used by a player to retrieve video ad.
See parameters
output: The XML output type. VAST, VMAP.
max_ad_duration: The duration range that an ad must match. Default value (20) is used if this parameter is not set.
sz: The size of master video ad slot. Default value (640x360) is used if this parameter is not set.
vpos: Indicates whether the ad request is being sent from pre-roll, mid-roll or post-roll.
vad_type: Indicates whether a linear or non-linear ad should be returned.
npa: Indicates that the ad request should be treated as non-personalized.
tfcd: The ad request for child-directed treatment.
In the 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/' } // Add this line
maven {url "https://jitpack.io"} // Add this line
}
...
allprojects {
repositories {
google()
jcenter() // Also, make sure jcenter() is included
maven { url 'https://developer.huawei.com/repo/' } //Add this line
maven {url "https://jitpack.io"} // Add this line
}
}
In the app-level build.gradle, include Huawei Ads dependency (required by the adapter) and the adapter
dependencies {
...
implementation 'com.github.Explore-In-HMS:huawei.ads.imaadapter:<latest_version>'
}
Solution has two different uses depending on ExoPlayer creation method or the selected player.
If ExoPlayer is used and it used with MediaItem to show video content and ads, adapter solution can be choose. Initializations of adapter is as follows;
HwImaAdapter.init(SimpleExoPlayer playerInstance, String adUnitId);
or
HwImaAdapter.init(PlayerView playerInstance,String HuaweiAdUnitId);
NOTE: HwImaAdapter.init method must be called just before SimpleExoPlayer.prepare() method called.
If ExoPlayer is used and MediaItem is not used or, player that compatible with Ima Ad Tag is used, converter solution can be choose. Initialization of converter is as follows;
HwTagConverter.init(String googleImaAdTagURL, String HuaweiAdUInitId, TagConverterListener() {
@Override
public void onSuccess(Uri uri) {
...
// SimpleExoPlayer.prepare()
...
}
});
If the operation is successful, the TagConverterListener's onSuccess function returns Uri instance that contains Huawei Roll Ads. Uri object is created based on the Ad Tag URL created on the Ad Manager.
NOTE: Video and ad content must be created after the callback is successful depends on the Uri instance.
Currently, adapter supports only linear ads depends on the Huawei Vast SDK.