本篇文章还是主要讲解uniapp知识,那么在uniapp中如何去实现监听通话的权限?接下来请看代码
// 可以放在App.vue当中 也可以放在页面的onload里面
if (plus.os.name == 'Android') {
plus.android.requestPermissions(
[ 'android.permission.ANSWER_PHONE_CALLS', //手动 挂断和接听 需要这个权限
"android.permission.MODIFY_AUDIO_SETTINGS", //手动 挂断和接听 需要这个权限
"android.permission.CALL_PHONE", //手动 挂断和接听 需要这个权限
"android.permission.READ_PHONE_STATE", //>监听电话状态 需要这个权限
"android.permission.READ_CALL_LOG", //获取号码需要这个权限
"android.permission.READ_AUDIO" // 录音权限
],
function(resultObj) {
var result = 0;
for (var i = 0; i < resultObj.granted.length; i++) {
var grantedPermission = resultObj.granted[i];
console.log('已获取的权限:' + grantedPermission);
result = 1
}
for (var i = 0; i < resultObj.deniedPresent.length; i++) {
var deniedPresentPermission = resultObj.deniedPresent[i];
console.log('拒绝本次申请的权限:' + deniedPresentPermission);
result = 0
}
for (var i = 0; i < resultObj.deniedAlways.length; i++) {
var deniedAlwaysPermission = resultObj.deniedAlways[i];
console.log('永久拒绝申请的权限:' + deniedAlwaysPermission);
result = -1
}
},
function(error) {
console.log('申请权限错误:' + error.code + " = " + error.message);
});
}
文章来源:https://www.toymoban.com/news/detail-592111.html
在页面中调用方法 监听通话状态文章来源地址https://www.toymoban.com/news/detail-592111.html
onLoad() {
this.getCallStatus()
},
methods: {
getCallStatus() {
let that = this;
let maintest = plus.android.runtimeMainActivity();//获取activity
let Contexttest = plus.android.importClass("android.content.Context");// 上下文
let telephonyManager = plus.android.importClass("android.telephony.TelephonyManager"); //通话管理
let telManager = plus.android.runtimeMainActivity().getSystemService(Contexttest.TELEPHONY_SERVICE);
let receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
onReceive: function(Contexttest, intent) {
plus.android.importClass(intent);
let phoneStatus = telManager.getCallState();
that.callStatus = phoneStatus; //电话状态 0->空闲状态 1->振铃状态 2->通话存在
switch (phoneStatus) {
case 0:
console.log("电话挂断")
break;
case 1:
console.log('振铃状态');
break;
case 2:
console.log('通话存在')
break;
}
}
});
let IntentFilter = plus.android.importClass('android.content.IntentFilter');
let filter = new IntentFilter();
filter.addAction(telephonyManager.ACTION_PHONE_STATE_CHANGED); // 监听电话状态
maintest.registerReceiver(receiver, filter); // //注册监听
}
}
到了这里,关于uniapp 安卓如何获取通话权限,监听通话情况的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!