HUAWEI Ads Kit provides the open advertising identifier (OAID) for you to deliver personalized ads and monetize traffic on Huawei devices.

OAID Capabilities

You can provide personalized marketing activities or commercial ads for users based on OAIDs to improve the conversion effect.

  1. Your app can call APIs of HUAWEI Ads to obtain a user's OAID and setting of Disable personalized ads.
  2. If the user turns off Disable personalized ads, your app can carry out personalized marketing activities and serve ads to this user based on the audiences to which the user's OAID belongs.
  3. If the user clicks an ad displayed in your app, your app can download and install the promoted app.
  4. Your app carries the OAID in impression, click, download, and other events to track and analyze the effect of marketing activities or commercial ads.

What You Will Create

In the codelab, you will create an app to access HUAWEI Ads. Your app will obtain an OAID and setting of Disable personalized ads.

What You Will Learn

In this codelab, you will learn how to integrate the OAID capabilities of HUAWEI Ads Kit.

Hardware Requirements

A Huawei mobile phone or tablet.

Software Requirements

HMS Core (APK) 2.6.2 or later.
To view the HMS Core (APK) version on a device, go to Settings > Apps > Apps and search for HMS Core.

Download the OAID-Initial project.

Download source code

Use Android Studio to open the OAID-Initial project.

1. Integrate the SDK.

Step 1: Configure the Maven repository address for the HUAWEI Ads SDK.

Open the build.gradle file in the root directory of your Android Studio project. Go to allprojects > repositories and configure the Maven repository address for the SDK.

allprojects { repositories { google() jcenter() maven { url 'https://developer.huawei.com/repo/' } } }

Step 2: Configure build dependencies.

Open the build.gradle file in the app directory. Configure build dependencies, and replace {version} with the latest version of HUAWEI Ads SDK. For details, please refer to Version Change History.

dependencies { implementation 'com.huawei.hms:ads-identifier:{version}' }

Step 3: Synchronize the modified files.

Step 4: (Mandatory) Configure the obfuscation scripts.


-keep class com.huawei.hms.ads.** { *; } -keep interface com.huawei.hms.ads.** { *; }

2. Call the static method getAdvertisingIdInfo to obtain the OAID.
Create a subthread and call the static method AdvertisingIdClient.getAdvertisingIdInfo(mContext) to obtain the OAID information. Do not call this method in a 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 { AdvertisingIdClient.Info info = AdvertisingIdClient.getAdvertisingIdInfo(context); if (null != info) { callback.onSuccuss(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 following information is displayed. You can click OAID Sample to view the result in the right figure.

Well done. You have successfully completed this codelab and learned how to:

For more information, please click the following link:

Related documents

You can click the button below to download the source code.

Download source code

Code copied