harmony 鸿蒙@ohos.identifier.oaid (广告标识服务)

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

@ohos.identifier.oaid (广告标识服务)

本模块提供开放匿名设备标识符(Open Anonymous Device Identifier, OAID,以下简称OAID)的获取和重置能力。

说明: 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

导入模块

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

identifier.getOAID

getOAID():Promise<string>

获取开放匿名设备标识符(Open Anonymous Device Identifier, OAID)。

需要权限: ohos.permission.APP_TRACKING_CONSENT

系统能力: SystemCapability.Advertising.OAID

返回值:

类型 说明
Promise<string> Promise对象。返回开放匿名设备标识符(Open Anonymous Device Identifier, OAID)。

错误码:

以下错误码的详细介绍请参见广告标识服务错误码参考

错误码ID 错误信息
17300001 System internal error.

示例:

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 promise success`);
  }).catch((err: BusinessError) => {
    hilog.info(0x0000, 'testTag', '%{public}s', `get oaid failed, message: ${err.message}`);
  })
} catch (err) {
  hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', err.code, err.message);
}

identifier.getOAID

getOAID(callback: AsyncCallback<string>): void

获取开放匿名设备标识符(Open Anonymous Device Identifier, OAID)。

需要权限: ohos.permission.APP_TRACKING_CONSENT

系统能力: SystemCapability.Advertising.OAID

参数:

参数 类型 必填 说明
callback AsyncCallback<string> 获取开放匿名设备标识符(Open Anonymous Device Identifier, OAID)的回调函数。

错误码:

以下错误码的详细介绍请参见广告标识服务错误码参考

错误码ID 错误信息
17300001 System internal error.

示例:

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) {
  hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', err.code, err.message);
}

identifier.resetOAID

resetOAID(): void

重置开放匿名设备标识符(Open Anonymous Device Identifier, OAID)。

系统接口: 此接口为系统接口。

系统能力: SystemCapability.Advertising.OAID

错误码:

以下错误码的详细介绍请参见广告标识服务错误码参考

错误码ID 错误信息
17300001 System internal error.

示例:

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

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

你可能感兴趣的鸿蒙文章

harmony 鸿蒙接口

harmony 鸿蒙系统公共事件定义(待停用)

harmony 鸿蒙系统公共事件定义

harmony 鸿蒙开发说明

harmony 鸿蒙企业设备管理概述(仅对系统应用开放)

harmony 鸿蒙BundleStatusCallback

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

harmony 鸿蒙@ohos.distributedBundle (分布式包管理)

harmony 鸿蒙@ohos.bundle (Bundle模块)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (企业设备管理扩展能力)

0  赞