PermissionRequestResult

The PermissionRequestResult module defines the result of a permission request. The result is returned when requestPermissionsFromUser is called to request permissions.

NOTE

  • The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • The APIs of this module can be used only in the stage model.

Attributes

System capability: SystemCapability.Security.AccessToken

Name Type Readable Writable Description
permissions Array<string> Yes No Permissions requested.
authResults Array<number> Yes No Result of the permission request.
- -1: The permission is not authorized and must be set in Settings without displaying a dialog box.
- 0: The permission is authorized.
- 2: The permission is not authorized due to an invalid request. The possible causes are as follows:
- The permission is not declared in the configuration file.
- The permission name is invalid.
- Certain conditions are not met when the permission is applied. For details, see ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION.

Usage

The permission request result is obtained through an atManager instance.

Example For details about how to obtain the context in the example, see Obtaining the Context of UIAbility.

import abilityAccessCtrl from '@ohos.abilityAccessCtrl';
import { BusinessError } from '@ohos.base';
import common from '@ohos.app.ability.common';

let atManager = abilityAccessCtrl.createAtManager();
try {
  let context: Context = getContext(this) as common.UIAbilityContext;
  atManager.requestPermissionsFromUser(context, ["ohos.permission.CAMERA"]).then((data) => {
      console.info("data:" + JSON.stringify(data));
      console.info("data permissions:" + data.permissions);
      console.info("data authResults:" + data.authResults);
  }).catch((err: BusinessError) => {
      console.info("data:" + JSON.stringify(err));
  })
} catch(err) {
  console.log(`catch err->${JSON.stringify(err)}`);
}