harmony 鸿蒙@ohos.identifier.oaid (OAID)

  • 2023-10-30
  • 浏览 (496)

@ohos.identifier.oaid (OAID)

The OAID module provides APIs for obtaining and resetting Open Anonymous Device Identifiers (OAIDs).

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.

Modules to Import

import identifier from '@ohos.identifier.oaid';

identifier.getOAID

getOAID():Promise<string>

Obtains an OAID. This API uses a promise to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.APP_TRACKING_CONSENT

System capability: SystemCapability.Advertising.OAID

Return value

Type Description
Promise<string> Promise used to return the OAID.

Error codes

For details about the following error codes, see OAID Error Codes.

ID Error Message
17300001 System internal error.

Example

import identifier from '@ohos.identifier.oaid';
import hilog from '@ohos.hilog'; 
import { BusinessError } from '@ohos.base';
 
try {  
  identifier.getOAID().then((data) => {
    const oaid: string = data;
    hilog.info(0x0000, 'testTag', '%{public}s', `get oaid by callback success`);
  }).catch((err: BusinessError) => {
    hilog.info(0x0000, 'testTag', '%{public}s', `get oaid failed, message: ${err.message}`);
  })
} catch (err: BusinessError) {
  hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', err.code, err.message);
}

identifier.getOAID

getOAID(callback: AsyncCallback<string>): void

Obtains an OAID. This API uses an asynchronous callback to return the result.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.APP_TRACKING_CONSENT

System capability: SystemCapability.Advertising.OAID

Parameters

Name Type Mandatory Description
callback AsyncCallback<string> Yes Callback used to return the OAID.

Error codes

For details about the following error codes, see OAID Error Codes.

ID Error Message
17300001 System internal error.

Example

import identifier from '@ohos.identifier.oaid';
import hilog from '@ohos.hilog'; 
import { BusinessError } from '@ohos.base';
 
try {
  identifier.getOAID((err: BusinessError, data) => {
    if (err.code) {
      hilog.info(0x0000, 'testTag', '%{public}s', `get oaid failed, message: ${err.message}`);
    } else {
      const oaid: string = data;
      hilog.info(0x0000, 'testTag', '%{public}s', `get oaid by callback success`);
    }
   });
} catch (err: BusinessError) {
  hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', err.code, err.message);
}

identifier.resetOAID

resetOAID(): void

Resets an OAID.

System API: This is a system API.

Model restriction: This API can be used only in the stage model.

Required permissions: ohos.permission.APP_TRACKING_CONSENT

System capability: SystemCapability.Advertising.OAID

Error codes

For details about the following error codes, see OAID Error Codes.

ID Error Message
17300001 System internal error.

Example

import identifier from '@ohos.identifier.oaid';
import hilog from '@ohos.hilog'; 
import { BusinessError } from '@ohos.base';

try {
  identifier.resetOAID();
} catch (err: BusinessError) {
  hilog.error(0x0000, 'testTag', 'reset oaid catch error: %{public}d %{public}s', err.code, err.message);
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞