• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.identifier.oaid (OAID)
2
3
4The **OAID** module provides APIs for obtaining and resetting Open Anonymous Device Identifiers (OAIDs).
5
6
7> **NOTE**
8>
9> 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.
10
11
12## Modules to Import
13
14```
15import identifier from '@ohos.identifier.oaid';
16```
17
18
19## identifier.getOAID
20
21getOAID():Promise<string>
22
23Obtains an OAID. This API uses a promise to return the result.
24
25**Model restriction**: This API can be used only in the stage model.
26
27**Required permissions**: ohos.permission.APP_TRACKING_CONSENT
28
29**System capability**: SystemCapability.Advertising.OAID
30
31**Return value**
32
33| Type| Description|
34| -------- | -------- |
35| Promise<string> | Promise used to return the OAID.|
36
37**Error codes**
38
39For details about the following error codes, see [OAID Error Codes](../errorcodes/errorcode-oaid.md).
40
41| ID| Error Message|
42| -------- | -------- |
43| 17300001 | System internal error. |
44
45**Example**
46```
47import identifier from '@ohos.identifier.oaid';
48import hilog from '@ohos.hilog';
49import { BusinessError } from '@ohos.base';
50
51try {
52  identifier.getOAID().then((data) => {
53    const oaid: string = data;
54    hilog.info(0x0000, 'testTag', '%{public}s', `get oaid by callback success`);
55  }).catch((err: BusinessError) => {
56    hilog.info(0x0000, 'testTag', '%{public}s', `get oaid failed, message: ${err.message}`);
57  })
58} catch (err: BusinessError) {
59  hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', err.code, err.message);
60}
61```
62
63
64## identifier.getOAID
65
66getOAID(callback: AsyncCallback<string>): void
67
68Obtains an OAID. This API uses an asynchronous callback to return the result.
69
70**Model restriction**: This API can be used only in the stage model.
71
72**Required permissions**: ohos.permission.APP_TRACKING_CONSENT
73
74**System capability**: SystemCapability.Advertising.OAID
75
76**Parameters**
77
78
79| Name| Type| Mandatory| Description|
80| -------- | -------- | -------- | -------- |
81| callback | AsyncCallback<string> | Yes| Callback used to return the OAID.|
82
83
84**Error codes**
85
86
87For details about the following error codes, see [OAID Error Codes](../errorcodes/errorcode-oaid.md).
88
89
90| ID| Error Message|
91| -------- | -------- |
92| 17300001 | System internal error. |
93
94
95**Example**
96```
97import identifier from '@ohos.identifier.oaid';
98import hilog from '@ohos.hilog';
99import { BusinessError } from '@ohos.base';
100
101try {
102  identifier.getOAID((err: BusinessError, data) => {
103    if (err.code) {
104      hilog.info(0x0000, 'testTag', '%{public}s', `get oaid failed, message: ${err.message}`);
105    } else {
106      const oaid: string = data;
107      hilog.info(0x0000, 'testTag', '%{public}s', `get oaid by callback success`);
108    }
109   });
110} catch (err: BusinessError) {
111  hilog.error(0x0000, 'testTag', 'get oaid catch error: %{public}d %{public}s', err.code, err.message);
112}
113```
114
115
116## identifier.resetOAID
117
118resetOAID(): void
119
120Resets an OAID.
121
122**System API**: This is a system API.
123
124**Model restriction**: This API can be used only in the stage model.
125
126**Required permissions**: ohos.permission.APP_TRACKING_CONSENT
127
128**System capability**: SystemCapability.Advertising.OAID
129
130**Error codes**
131
132For details about the following error codes, see [OAID Error Codes](../errorcodes/errorcode-oaid.md).
133
134| ID| Error Message|
135| -------- | -------- |
136| 17300001 | System internal error. |
137
138**Example**
139```
140import identifier from '@ohos.identifier.oaid';
141import hilog from '@ohos.hilog';
142import { BusinessError } from '@ohos.base';
143
144try {
145  identifier.resetOAID();
146} catch (err: BusinessError) {
147  hilog.error(0x0000, 'testTag', 'reset oaid catch error: %{public}d %{public}s', err.code, err.message);
148}
149```
150