血魔东健
血魔东健
  • 发布:2019-05-22 13:02
  • 更新:2019-10-31 11:44
  • 阅读:2742

h5+ app 能否接收安卓app发送的广播

分类:HTML5+

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回调

2019-05-22 13:02 负责人:无 分享
已邀请:
z***@163.com

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

该问题目前已经被锁定, 无法添加新回复