有两个问题:
一、动态申请摄像头权限,用户点同意后没有相关回调,用户需要第二次点击相应功能才可以使用
二、用户点击禁止且不再提醒的时候,如何做判断
相关代码如下:
function checkPermission(ArrPermissions, callback) {
let os = uni.getSystemInfoSync().platform
if (os == 'android') {
let Build = plus.android.importClass("android.os.Build")
let Manifest = plus.android.importClass("android.Manifest")
let MainActivity = plus.android.runtimeMainActivity();
//let context=main.getApplicationContext(); //未用到,在此仅供参考
let hasPermission = true;
for (let permission of ArrPermissions) {
if (Build.VERSION.SDK_INT >= 23) {
let result = MainActivity.checkSelfPermission(permission)
console.info("权限校验结果=" + result)
//没有权限
if (result == -1) {
//跳转到应用详情页面
//goAndroidSetting()
hasPermission = false
break
}
}
}
if (!hasPermission) {
let REQUEST_CODE_CONTACT = 101;
if (Build.VERSION.SDK_INT >= 23) {
//这里请求权限后,无法获取到结果,有没有好的处理方式
MainActivity.requestPermissions(ArrPermissions, REQUEST_CODE_CONTACT);
}
} else {
if (callback) callback()
}
} else if (os == 'ios') {
if (callback) callback()
}
}
function goAndroidSetting() {
let Uri = plus.android.importClass("android.net.Uri");
let Settings = plus.android.importClass("android.provider.Settings");
let context = plus.android.runtimeMainActivity();
let packageURI = Uri.parse("package:io.dcloud.HBuilder");
let intent = plus.android.newObject("android.content.Intent", Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
context.startActivity(intent);
}
module.exports = {
checkPermission,
goAndroidSetting
}