initBroadcast() {
let _this = this;
var main = plus.android.runtimeMainActivity();
var receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: function(context, intent) {
plus.android.importClass(intent);
let code = intent.getStringExtra("data"); // 换你的广播标签
console.log('扫码获取的code',code)
}
});
console.log(receiver,123123)
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
var filter = new IntentFilter();
filter.addAction('com.rscja.scanner.action.scanner.RFID'); //自定义广播ACTION
main.registerReceiver(receiver, filter);
},
离开了这个页面 console.log('扫码获取的code',code)这段代码还会执行,再次进入页面会执行两次,返回后在进入会执行三次,以此类推,请问有什么办法解决吗?
12:06:00.156 扫码获取的code, E28068940000502B56F38C7F
at pages/index/index.vue:45
12:06:03.256 onunload at pages/index/index.vue:34 这里是分割线,进入这个页面两次,运行了一次执行了两次方法,
12:06:08.750 扫码获取的code, E28068940000502B56F38C7F
at pages/index/index.vue:45
12:06:08.756 扫码获取的code, E28068940000502B56F38C7F
at pages/index/index.vue:45
0 个回复