HarmonyOS 鸿蒙Next ability权限弹窗不弹出
HarmonyOS 鸿蒙Next ability权限弹窗不弹出
uiability中代码如下(main.json5中权限已经说明,走了弹窗跳出log但是没有弹出来,为什么):
// 权限校验
async checkPermissions(): Promise<void> {
const permissions: Array<Permissions> = [‘ohos.permission.GET_NETWORK_INFO’,
‘ohos.permission.INTERNET’,
‘ohos.permission.APP_TRACKING_CONSENT’,
‘ohos.permission.STORE_PERSISTENT_DATA’,
‘ohos.permission.LOCATION_IN_BACKGROUND’,
];
const accessManager = abilityAccessCtrl.createAtManager();
try {
const bundleFlags = bundleManager.BundleFlag.GET_BUNDLE_INFO_WITH_APPLICATION;
const bundleInfo = await bundleManager.getBundleInfoForSelf(bundleFlags);
// 遍历数组并校验
for (const permission of permissions) {
const grantStatus = await accessManager.checkAccessToken(bundleInfo.appInfo.accessTokenId, permission);
if (grantStatus === abilityAccessCtrl.GrantStatus.PERMISSION_DENIED) {
accessManager.requestPermissionsFromUser(this.context, [permission]).then(() => {
console.log(‘leo’, permission + ‘弹窗跳出’)
});
console.log(‘leo’, permission + ‘没有权限’)
}
}
} catch (err) {
console.error(‘EntryAbility’, ‘checkPermissions’,Catch err: ${err}
);
return;
}
}
2 回复
HarmonyOS鸿蒙Next中ability权限弹窗不弹出的问题,可能是由于用户之前拒绝了权限并勾选了“不再询问”。开发者应引导用户理解权限的重要性,并在必要时指导用户手动到系统设置中开启权限。检查代码中权限请求的逻辑是否正确,确保遵循鸿蒙系统的权限管理规范。如果问题依旧没法解决,请加我微信,我的微信是itying888。