目录

Obtaining an AAID

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:

Use Cases

Scenarios where an AAID may change include but are not limited to the following:

Constraints

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).

API Description

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.

Obtaining an AAID

  1. 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;
  2. 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);
    }