• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.identifier.oaid (OAID)
2
3The **OAID** module provides APIs for obtaining Open Anonymous Device Identifiers (OAIDs).
4
5> **NOTE**
6> 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.
7> To use the APIs for obtaining OAIDs, you must [request the ohos.permission.APP_TRACKING_CONSENT permission](../../security/AccessToken/request-user-authorization.md).
8
9## Modules to Import
10
11```ts
12import { identifier } from '@kit.AdsKit';
13```
14
15## identifier.getOAID
16
17getOAID(): Promise<string>
18
19Obtains an OAID. This API uses a promise to return the result.
20
21**Required permissions**: ohos.permission.APP_TRACKING_CONSENT
22
23**System capability**: SystemCapability.Advertising.OAID
24
25**Return value**
26
27| Type                   | Description                                                                                                                                                                                                                                                                                                                                                                    |
28|-----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
29| Promise&lt;string&gt; | Promise used to return the OAID.<br>1. If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the permission is allowed, the OAID is returned.<br>2. If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the permission is disallowed, 00000000-0000-0000-0000-000000000000 is returned.<br>3. If the application has not configured the permission **ohos.permission.APP_TRACKING_CONSENT**, 00000000-0000-0000-0000-000000000000 is returned.|
30
31**Error codes**
32
33For details about the following error codes, see [OAID Error Codes](errorcode-oaid.md).
34
35| ID   | Error Message                            |
36|----------|----------------------------------|
37| 17300001 | System&nbsp;internal&nbsp;error. |
38
39**Example**
40
41```ts
42import { identifier } from '@kit.AdsKit';
43import { BusinessError } from '@kit.BasicServicesKit';
44import { hilog } from '@kit.PerformanceAnalysisKit';
45
46identifier.getOAID().then((data) => {
47  const oaid: string = data;
48  hilog.info(0x0000, 'testTag', `Succeed in getting oaid. Oaid is ${oaid}`);
49}).catch((err: BusinessError) => {
50  hilog.error(0x0000, 'testTag', `Fail to get oaid. Code is ${err.code}, message is ${err.message}`);
51})
52```
53
54## identifier.getOAID
55
56getOAID(callback: AsyncCallback&lt;string&gt;): void
57
58Obtains an OAID. This API uses an asynchronous callback to return the result.
59
60**Required permissions**: ohos.permission.APP_TRACKING_CONSENT
61
62**System capability**: SystemCapability.Advertising.OAID
63
64**Parameters**
65
66| Name     | Type                         | Mandatory| Description                                                                                                                                                                                                                                                                                                                                                               |
67|----------|-----------------------------|----|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
68| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the OAID.<br>1. If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the permission is allowed, the OAID is returned.<br>2. If the application has configured the permission **ohos.permission.APP_TRACKING_CONSENT** and the permission is disallowed, 00000000-0000-0000-0000-000000000000 is returned.<br>3. If the application has not configured the permission **ohos.permission.APP_TRACKING_CONSENT**, 00000000-0000-0000-0000-000000000000 is returned.|
69
70**Error codes**
71
72For details about the following error codes, see [OAID Error Codes](errorcode-oaid.md).
73
74| ID   | Error Message                            |
75|----------|----------------------------------|
76| 17300001 | System&nbsp;internal&nbsp;error. |
77
78**Example**
79
80```ts
81import { identifier } from '@kit.AdsKit';
82import { BusinessError } from '@kit.BasicServicesKit';
83import { hilog } from '@kit.PerformanceAnalysisKit';
84
85identifier.getOAID((err: BusinessError, data: string) => {
86  if (err.code) {
87    hilog.error(0x0000, 'testTag', `Fail to get oaid. Code is ${err.code}, message is ${err.message}`);
88  } else {
89    const oaid: string = data;
90    hilog.info(0x0000, 'testTag', `Succeed in getting oaid. Oaid is ${oaid}`);
91  }
92});
93```
94