An Anonymous Application Identifier (AAID) identifies an app instance running on a smart mobile device. It can be accessed only by that specific app instance and remains valid throughout the app installation period. The AAID is 36 characters long. Compared with device-level hardware IDs that cannot be reset, AAIDs offer improved privacy.
To be specific, an AAID has the following features:
Anonymous, no privacy risk: An AAID is not associated with any existing identifiers. Besides, each app can only access its own AAID.
For apps from the same developer, which are running on the same device, each of them has its own AAID.
For apps from different developers, which are running on the same device, each of them has its own AAID.
For different apps from the same developer, which are running on different devices, each of them has its own AAID.
For apps from different developers, which are running on different devices, each of them has its own AAID.
Scenarios where an AAID may change include but are not limited to the following:
An app is reinstalled.
An app calls the API for deleting the AAID.
A user restores the device to its factory settings.
A user clears the app data.
The capability of obtaining an AAID is supported on phones, tablets, and PCs/2-in-1 devices. Support for wearables is available starting from 5.1.0(18), and for TVs starting from 5.1.1(19).
The APIs use either a callback or promise to return the result. The table below lists only the APIs that use a promise. The APIs that use a callback provide the same functions as their counterparts that use a promise.
| API | Description |
|---|---|
| getAAID(): Promise<string> | Obtains an AAID. This API uses a promise to return the result. |
| deleteAAID(): Promise<void> | Deletes an AAID. This API uses a promise to return the result. |
Import the AAID module and related common modules.
import { AAID } from '@kit.PushKit';
import { BusinessError } from '@kit.BasicServicesKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
const DOMAIN = 0x0000; Call the AAID.getAAID() method to obtain an AAID.
try {
// data indicates the obtained anonymous ID of the app.
AAID.getAAID((err: BusinessError, data: string) => {
if (err) {
hilog.error(DOMAIN, 'testTag', 'Failed to get AAID: %{public}d %{public}s', err.code, err.message);
} else {
hilog.info(DOMAIN, 'testTag', 'Succeeded in getting AAID');
}
});
} catch (err) {
let e: BusinessError = err as BusinessError;
hilog.error(DOMAIN, 'testTag', 'Failed to get AAID: %{public}d %{public}s', e.code, e.message);
}