You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.5 KiB
65 lines
1.5 KiB
2 years ago
|
<template>
|
||
|
<view class="content"></view>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import {
|
||
|
onLoad,
|
||
|
onShow,
|
||
|
onHide,
|
||
|
onUnload
|
||
|
} from '@dcloudio/uni-app'
|
||
|
import { reactive } from "vue";
|
||
|
export default {
|
||
|
setup(){
|
||
|
let details=reactive({
|
||
|
activity: null,
|
||
|
receiver: null,
|
||
|
intentFilter: null
|
||
|
})
|
||
|
onLoad(()=>{
|
||
|
initScan()
|
||
|
startScan();
|
||
|
})
|
||
|
onHide(()=>{
|
||
|
stopScan();
|
||
|
})
|
||
|
onUnload(()=>{
|
||
|
details.stopScan();
|
||
|
uni.$off('scancodedate')
|
||
|
})
|
||
|
function initScan() {
|
||
|
if (plus) {
|
||
|
details.activity = plus.android.runtimeMainActivity(); //获取activity
|
||
|
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
|
||
|
details.intentFilter = new IntentFilter();
|
||
|
details.intentFilter.addAction('nlscan.action.SCANNER_RESULT') // 换你的广播动作
|
||
|
details.receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
|
||
|
onReceive: function(context, intent) {
|
||
|
console.log("intent", intent)
|
||
|
plus.android.importClass(intent);
|
||
|
let content = intent.getStringExtra('SCAN_BARCODE1'); // 换你的广播标签
|
||
|
uni.$emit('scancodedate', content.replace(/\n/g, ""))
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
}
|
||
|
function startScan() {
|
||
|
details.activity.registerReceiver(details.receiver, details.intentFilter);
|
||
|
}
|
||
|
function stopScan() {
|
||
|
details.activity.unregisterReceiver(details.receiver);
|
||
|
}
|
||
|
return {
|
||
|
startScan,
|
||
|
stopScan,
|
||
|
initScan,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style>
|
||
|
</style>
|