h5+ app 能否接收安卓app发送的广播?怎么接收?安卓那边怎么发送?
function initReceiver() {
console.log('Init scan broadcast receiver ...');
var main = plus.android.runtimeMainActivity();
var receiver = plus.android.implements('io.dcloud.android.content.BroadcastReceiver', {
onReceive: function(context,intent){//实现onReceiver回调函数
plus.android.importClass(intent);//通过intent实例引入intent类,方便以后的‘.’操作
var action = intent.getAction();
console.log(action)
...
});
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
var filter = new IntentFilter();
filter.addAction(ACTION_FRONT_OUTPUT);
filter.addAction(ACTION_BACKGROUND_OUTPUT);
filter.addAction(ECG_TARGET_ACTION);
filter.addAction(ECG_TARGET_PAUSE_ACTION);
filter.addAction(DIAGNOSIS_TARGET_ACTION);
main.registerReceiver(receiver,filter);//注册监听
return receiver;
}
现在的问题是无法获取onReceive回调
1 个回复
z***@163.com - 程序员
你好,问一下你这段代码什么时候调用的? 我写的报错
Attempt to read from field 'java.lang.Class io.dcloud.invocation.c.b' on a null object reference;at io.dcloud.PandoraEntryActivity.registerReceiver