@ohos.identifier.oaid (OAID)
This module provides the capability of obtaining and resetting the Open Anonymous Device Identifier (OAID).
NOTE
The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
To use the API for obtaining the OAID, you need to request user authorization (the permission is enabled by default): ohos.permission.APP_TRACKING_CONSENT.
Modules to Import
import { identifier } from '@kit.AdsKit';
identifier.getOAID
getOAID(): Promise<string>
Obtains the OAID. This API uses a promise to return the result.
Required permissions: ohos.permission.APP_TRACKING_CONSENT
System capability: SystemCapability.Advertising.OAID
Return value
| Type | Description |
|---|---|
| Promise<string> | Promise object, which returns the OAID. 1. If the app has configured the ohos.permission.APP_TRACKING_CONSENT permission and the cross-app association access permission is allowed, the OAID is returned. 2. If the app has configured the ohos.permission.APP_TRACKING_CONSENT permission and the cross-app association access permission is disallowed, 00000000-0000-0000-0000-000000000000 is returned. 3. If the app has not configured the ohos.permission.APP_TRACKING_CONSENT permission, 00000000-0000-0000-0000-000000000000 is returned. |
Error codes
For details about the error codes, see OAID Error Codes.
| ID | Error Message |
|---|---|
| 17300001 | System internal error. |
Example
import { identifier } from '@kit.AdsKit';
identifier.getOAID().then((data: string) => {
const oaid: string = data;
});
identifier.getOAID
getOAID(callback: AsyncCallback<string>): void
Obtains the OAID. This API uses an asynchronous callback to return the result.
Required permissions: ohos.permission.APP_TRACKING_CONSENT
System capability: SystemCapability.Advertising.OAID
Parameters
| Parameter Name | Type | Mandatory | Description |
|---|---|---|---|
| callback | AsyncCallback<string> | Yes | Callback function, which returns the OAID. 1. If the app has configured the ohos.permission.APP_TRACKING_CONSENT permission and the cross-app association access permission is allowed, the OAID is returned. 2. If the app has configured the ohos.permission.APP_TRACKING_CONSENT permission and the cross-app association access permission is disallowed, 00000000-0000-0000-0000-000000000000 is returned. 3. If the app has not configured the ohos.permission.APP_TRACKING_CONSENT permission, 00000000-0000-0000-0000-000000000000 is returned. |
NOTE
The setting item of cross-app association access permission was named app tracking access permission in HarmonyOS NEXT Developer Beta5 and earlier versions.
Error codes
For details about the error codes, see OAID Error Codes.
| ID | Error Message |
|---|---|
| 17300001 | System internal error. |
Example
import { identifier } from '@kit.AdsKit';
import { BusinessError } from '@kit.BasicServicesKit';
identifier.getOAID((err: BusinessError, data: string) => {
if (err.code) {
return;
}
const oaid: string = data;
});