uni-app 监听电话状态
let maintest = plus.android.runtimeMainActivity();
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);
console.log(intent.getAction());
// let telephonyManager = plus.android.importClass("android.telephony.TelephonyManager");
// let telephonyManager=plus.android.runtimeMainActivity().getSystemService(Contexttest.TELEPHONY_SERVICE);
let phonetype=telManager.getCallState();
let phoneNumber = intent.getStringExtra(telephonyManager.EXTRA_INCOMING_NUMBER);
console.log("phonetype:"+phonetype); //电话状态 0->空闲状态 1->振铃状态 2->通话存在
console.log(); //电话号
switch (phonetype) {
case 0:
_this.getCallLog();
console.log('aaa')
break;
case 1:
console.log('bbb')
break;
case 2:
console.log('ccc')
break;
}
// _t.state.push({state:phonetype == 0?'空闲状态':phonetype == 1?'振铃状态':'通话存在', time:dateFormat('hh:mm:ss')})
}
});
let IntentFilter = plus.android.importClass('android.content.IntentFilter');
let filter = new IntentFilter();
filter.addAction(telephonyManager.ACTION_PHONE_STATE_CHANGED);
maintest.registerReceiver(receiver, filter);
之前使用这个是可以监听拨打电话的状态的,但是6月中旬之后就监听不到了,是不是安卓系统升级的原因,有没有什么其他办法可以监听到吗?
我是纸飞机 (作者)
好的,解决了谢谢您
2022-06-28 15:29
十二112
回复 2***@qq.com: 不客气
2022-06-28 15:58