Ads Kit provides the open advertising identifier (OAID) for you to deliver personalized ads and monetize traffic on Huawei devices.
Based on OAIDs, you can serve personalized marketing campaigns and commercial ads to users, thereby improving conversions. The process is as follows:
In this codelab, you will create an app for traffic monetization via Ads Kit. Your app will be able to obtain users' OAIDs and settings of Disable personalized ads.
In this codelab, you will learn how to integrate the OAID capabilities of Ads Kit.
A Huawei phone, tablet, or smart display running EMUI 3.0 or later
Android app development basics
Click here to view and download the sample code of the OAID-Initial project.
Use Android Studio to open the OAID-Initial project.
The procedure for configuring the Maven repository address in Android Studio is different for Gradle plugin earlier than 7.0, Gradle plugin 7.0, and Gradle plugin 7.1 or later. Click a relevant link below to find the configuration procedure for the specific Gradle plugin version.
Gradle plugin earlier than 7.0 | Gradle plugin 7.0 | Gradle plugin 7.1 or later |
Gradle plugin earlier than 7.0
i. Open your project-level build.gradle file.
ii. Add the Maven repository.
buildscript {
repositories {
google()
jcenter()
// Configure the Maven repository address for the HUAWEI Ads SDK.
maven {url 'https://developer.huawei.com/repo/'}
}
}
allprojects {
repositories {
google()
jcenter()
// Configure the Maven repository address for the HUAWEI Ads SDK.
maven {url 'https://developer.huawei.com/repo/'}
}
}
Gradle plugin 7.0
i. Open your project-level build.gradle file.
ii. Add the Maven repository.
Configure the Maven repository address under buildscript > repositories.
buildscript {
repositories {
google()
jcenter()
// Configure the Maven repository address for the HUAWEI Ads SDK.
maven {url 'https://developer.huawei.com/repo/'}
}
}
iii. Open the project-level settings.gradle file and configure the Maven repository address.
dependencyResolutionManagement {
...
repositories {
google()
jcenter()
// Configure the Maven repository address for the HUAWEI Ads SDK.
maven {url 'https://developer.huawei.com/repo/'}
}
}
Gradle plugin 7.1 or later
Open the project-level settings.gradle file and configure the Maven repository address.
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
// Configure the Maven repository address for the HUAWEI Ads SDK.
maven { url 'https://developer.huawei.com/repo/' }
}
}
dependencyResolutionManagement {
...
repositories {
google()
mavenCentral()
// Configure the Maven repository address for the HUAWEI Ads SDK.
maven { url 'https://developer.huawei.com/repo/' }
}
}
dependencies {
implementation 'com.huawei.hms:ads-identifier:{version}'
}
-keep class com.huawei.hms.ads.** { *; }
-keep interface com.huawei.hms.ads.** { *; }
Create a subthread and call the static method AdvertisingIdClient.getAdvertisingIdInfo(mContext) to obtain the OAID information. Do not call this method in the main thread. The sample code is as follows:
public static void getOaid(Context context, OaidCallback callback) {
if (null == context || null == callback) {
Log.e(TAG, "invalid input param");
return;
}
try {
// Obtain the OAID information. Do not call this method in the main thread.
AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(context);
if (null != info) {
callback.onSuccess(info.getId(), info.isLimitAdTrackingEnabled());
} else {
callback.onFail("oaid is null");
}
} catch (IOException e) {
Log.e(TAG, "getAdvertisingIdInfo IOException");
callback.onFail("getAdvertisingIdInfo IOException");
}
}
Compile the OAID-Initial project to generate an APK file and install the APK file on a device. After the app is launched, the page shown in the figure on the left is displayed. You can tap OAID Sample to view the result in the figure on the right.
Well done. You have successfully completed this codelab and learned how to integrate the OAID capabilities of Ads Kit.
For more information, please refer to related documents.
You can also click here and download the source code.