var main = plus.android.runtimeMainActivity();
var Context = plus.android.importClass("android.content.Context");
var telephonyManager = plus.android.importClass("android.telephony.TelephonyManager");
var telephonyManager=plus.android.runtimeMainActivity().getSystemService(Context.TELEPHONY_SERVICE);
var receiver=plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
onReceive: function(context, intent) { //实现onReceiver回调函数
plus.android.importClass(intent);
console.log(intent.getAction());
var telephonyManager = plus.android.importClass("android.telephony.TelephonyManager");
var telephonyManager=plus.android.runtimeMainActivity().getSystemService(Context.TELEPHONY_SERVICE);
var phonetype=telephonyManager.getCallState();
var phoneNumber = intent.getStringExtra(telephonyManager.EXTRA_INCOMING_NUMBER);
/**
* public static final int CALL_STATE_IDLE = 0; //空闲状态
* public static final int CALL_STATE_RINGING = 1; //振铃状态
* public static final int CALL_STATE_OFFHOOK = 2; //至少有一个通话存在
*/
console.log("phonetype:"+phonetype);
console.log("phonetype:"+phoneNumber);
if(phonetype==2){
main.unregisterReceiver(receiver);
}
}
});
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
var filter = new IntentFilter();
filter.addAction(telephonyManager.ACTION_PHONE_STATE_CHANGED); //监听开关
main.registerReceiver(receiver, filter); //注册监听
亲测可用!
3 个评论
要回复文章请先登录或注册
3***@qq.com
Mankii
51ZionLin