1# @ohos.identifier.oaid (广告标识服务) 2 3 4本模块提供开放匿名设备标识符(Open Anonymous Device Identifier, OAID,以下简称OAID)的获取和重置能力。 5 6 7> **说明:** 8> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 9 10 11## 导入模块 12 13``` 14import identifier from '@ohos.identifier.oaid'; 15``` 16 17 18## identifier.getOAID 19 20getOAID():Promise<string> 21 22获取开放匿名设备标识符(Open Anonymous Device Identifier, OAID)。 23 24**需要权限:** ohos.permission.APP_TRACKING_CONSENT 25 26**系统能力:** SystemCapability.Advertising.OAID 27 28**返回值:** 29 30| 类型 | 说明 | 31| -------- | -------- | 32| Promise<string> | Promise对象。返回开放匿名设备标识符(Open Anonymous Device Identifier, OAID)。 | 33 34**错误码:** 35 36以下错误码的详细介绍请参见[广告标识服务错误码参考](../errorcodes/errorcode-oaid.md)。 37 38| 错误码ID | 错误信息 | 39| -------- | -------- | 40| 17300001 | System internal error. | 41 42**示例:** 43``` 44import identifier from '@ohos.identifier.oaid'; 45import hilog from '@ohos.hilog'; 46import { BusinessError } from '@ohos.base'; 47 48try { 49 identifier.getOAID().then((data) => { 50 const oaid: string = data; 51 hilog.info(0x0000, 'testTag', '%{public}s', `get oaid by promise success`); 52 }).catch((err: BusinessError) => { 53 hilog.info(0x0000, 'testTag', '%{public}s', `get oaid failed, message: ${err.message}`); 54 }) 55} catch (err) { 56 hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', err.code, err.message); 57} 58``` 59 60 61## identifier.getOAID 62 63getOAID(callback: AsyncCallback<string>): void 64 65获取开放匿名设备标识符(Open Anonymous Device Identifier, OAID)。 66 67**需要权限:** ohos.permission.APP_TRACKING_CONSENT 68 69**系统能力:** SystemCapability.Advertising.OAID 70 71**参数:** 72 73 74| **参数**名 | **类型** | 必填 | 说明 | 75| -------- | -------- | -------- | -------- | 76| callback | AsyncCallback<string> | 是 | 获取开放匿名设备标识符(Open Anonymous Device Identifier, OAID)的回调函数。 | 77 78 79**错误码:** 80 81 82以下错误码的详细介绍请参见[广告标识服务错误码参考](../errorcodes/errorcode-oaid.md)。 83 84 85| 错误码ID | 错误信息 | 86| -------- | -------- | 87| 17300001 | System internal error. | 88 89 90**示例:** 91``` 92import identifier from '@ohos.identifier.oaid'; 93import hilog from '@ohos.hilog'; 94import { BusinessError } from '@ohos.base'; 95 96try { 97 identifier.getOAID((err: BusinessError, data) => { 98 if (err.code) { 99 hilog.info(0x0000, 'testTag', '%{public}s', `get oaid failed, message: ${err.message}`); 100 } else { 101 const oaid: string = data; 102 hilog.info(0x0000, 'testTag', '%{public}s', `get oaid by callback success`); 103 } 104 }); 105} catch (err) { 106 hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', err.code, err.message); 107} 108``` 109 110 111## identifier.resetOAID 112 113resetOAID(): void 114 115重置开放匿名设备标识符(Open Anonymous Device Identifier, OAID)。 116 117**系统接口:** 此接口为系统接口。 118 119**系统能力:** SystemCapability.Advertising.OAID 120 121**错误码:** 122 123以下错误码的详细介绍请参见[广告标识服务错误码参考](../errorcodes/errorcode-oaid.md)。 124 125| 错误码ID | 错误信息 | 126| -------- | -------- | 127| 17300001 | System internal error. | 128 129**示例:** 130``` 131import identifier from '@ohos.identifier.oaid'; 132import hilog from '@ohos.hilog'; 133 134try { 135 identifier.resetOAID(); 136} catch (err) { 137 hilog.error(0x0000, 'testTag', 'reset oaid catch error: %{public}d %{public}s', err.code, err.message); 138} 139``` 140