uniapp中在安卓端中若是已经拒绝过一次申请拨打电话权限后则再次,调用uni.makemakePhoneCall会到成功的回调,但是却没有反应
错误代码
uni.makePhoneCall({
phoneNumber,
success:(res)=>{
console.log('拨打电话成功')
console.log(res)
},
fail:(err)=>{
console.log('拨打电话失败')
console.log(err)
}
})
改进后
makePhone(phoneNumber) {
// console.log(phoneNumber)
plus.android.requestPermissions(
['android.permission.CALL_PHONE'],
function (resultObj) {
let result = 0
for (let i = 0; i < resultObj.granted.length; i++) {
let grantedPremission = resultObj.granted[i]
console.log('已获取权限',grantedPremission)
result =1
}
for(let i =0 ;i<resultObj.deniedPresent.length;i++){
let deniedPresentPremission = resultObj.deniedPresent[i]
console.log('拒绝本次申请的权限',deniedPresentPremission)
result=0
}
for(let i=0;i>resultObj.deniedAlways.length;i++){
let deniedAlwaysPremission = resultObj.deniedAlways[i]
console.log('永久拒绝申请的权限',deniedAlwaysPremission)
result=-1
}
if(result==1){
uni.makePhoneCall({
phoneNumber,
success:(res)=>{
console.log('拨打电话成功')
console.log(res)
},
fail:(err)=>{
console.log('拨打电话失败')
console.log(err)
}
})
}else{
this.tips('请在设置中打开拨打电话权限')
}
},
function(err){
console.log('申请权限错误:' + error.code + " = " + error.message);
}
)
}