代码拉取完成,页面将自动刷新
<template>
<view></view>
</template>
<script>
var _codeQueryTag = false;
export default {
data() {
return {
activity: null,
receiver: null,
intentFilter: null
}
},
created: function(option) {
this.initScan()
this.startScan();
},
onHide: function() {
this.stopScan();
},
destroyed: function() {
//页面退出时一定要卸载监听,否则下次进来时会重复,造成扫一次出2个以上的结果/
this.stopScan();
},
methods: {
initScan() {
let _this = this;
this.activity = plus.android.runtimeMainActivity(); //获取activity
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
this.intentFilter = new IntentFilter();
this.intentFilter.addAction('com.android.server.scannerservice.broadcast') // 换你的广播动作
this.receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: function(context, intent) {
plus.android.importClass(intent);
let content = intent.getStringExtra('scannerdata'); // 换你的广播标签
_this.querycode(content);
}
});
},
startScan() {
this.activity.registerReceiver(this.receiver, this.intentFilter);
},
stopScan() {
this.activity.unregisterReceiver(this.receiver);
},
querycode: function(code) {
console.log('=====',code)
//防重复
if (_codeQueryTag) return false;
_codeQueryTag = true;
setTimeout(function() {
_codeQueryTag = false;
}, 150);
console.log('scancodedate',code)
uni.$emit('scancodedate', code);
}
}
}
</script>
<style>
</style>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。