HarmonyOS 鸿蒙Next 求助:点击按钮动态获取授权,无法弹窗
HarmonyOS 鸿蒙Next 求助:点击按钮动态获取授权,无法弹窗
点击按钮动态授权,但是无法弹窗
private permissions: Array<Permissions> = [‘ohos.permission.APPROXIMATELY_LOCATION’,
‘ohos.permission.LOCATION’];
async reqPermissionsFromUser() {
let atMgr = abilityAccessCtrl.createAtManager();
await atMgr.requestPermissionsFromUser(this.context, this.permissions).then((data) => {
let grantStatus: Array<number> = data.authResults;
let length: number = grantStatus.length;
for (let i = 0; i < length; i++) {
if (grantStatus[i] === 0) {
console.log(‘HUWEI 已授权’);
} else {
// 用户拒绝授权,提示用户必须授权才能访问当前页面的功能,并引导用户到系统设置中打开相应的权限
console.log(‘HUWEI 未授权’);
}
}
}).catch((err: BusinessError) => {
console.error(Failed to request permissions from user. Code is ${err.code}, message is ${err.message}
);
})
}
报错:
E <1690>GetDecorHeight: Get app window decor height failed
E [ui_ability_impl.cpp(operator():410)]null applicationContext or lifecycleCallback
关于HarmonyOS 鸿蒙Next 求助:点击按钮动态获取授权,无法弹窗的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。
4 回复
找HarmonyOS工作还需要会Flutter的哦,有需要Flutter教程的可以学学大地老师的教程,很不错,B站免费学的哦:https://www.bilibili.com/video/BV1S4411E7LY/?p=17
请问楼主问题解决了吗?
请问你是在UIAbility中向用户申请授权,还是在UI中向用户申请授权。在不同地方向用户申请授权,有些差异,可以参考一下这里官方文档。
let context = getContext(this) as common.UIAbilityContext;