harmony 鸿蒙PermissionRequestResult

  • 2022-12-22
  • 浏览 (556)

PermissionRequestResult

The PermissionRequestResult module provides the result of a permission request.

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.Ability.AbilityRuntime.Core

Name Type Readable Writable Description
permissions Array<string> Yes No Permissions requested.
authResults Array<number> Yes No Whether the requested permissions are granted or denied. The value 0 means that the requests permissions are granted, and a non-zero value means the opposite.

How to Use

The permission request result is obtained through an AbilityStage instance.

Example

import Ability from '@ohos.application.Ability'
export default class MainAbility extends Ability {
  onWindowStageCreate(windowStage) {
    var permissions=['com.example.permission']
    var permissionRequestResult;
    this.context.requestPermissionsFromUser(permissions,(err,result) => {
      if(err){
        console.log('requestPermissionsFromUserError: ' + JSON.stringify(err));
      }else{
        permissionRequestResult=result;
        console.log('permissionRequestResult: ' + JSON.stringify(permissionRequestResult));
      }    
    });
  }
}

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

harmony 鸿蒙@ohos.WorkSchedulerExtensionAbility (Work Scheduler Callbacks)

0  赞