鸿蒙next申请权限
写在入口UIAbility
里面
PERMISSIONS: Array<Permissions> = ['ohos.permission.READ_MEDIA','ohos.permission.WRITE_MEDIA'];
onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
let atManager: abilityAccessCtrl.AtManager = abilityAccessCtrl.createAtManager();
try {
atManager.requestPermissionsFromUser(this.context, this.PERMISSIONS, (err, data) => {
if (err) {
console.info('testTag', `requestPermissionsFromUser data: ${JSON.stringify(err)}`);
} else {
console.info('testTag', `requestPermissionsFromUser data: ${JSON.stringify(data)}`);
}
});
} catch (err) {
console.info('testTag', `catch err->${JSON.stringify(err)}`);
}
}