uni-app基于nativejs实现PDA手持终端扫码广播信息接收

pda手持终端的开发,大多是用原生安卓开发的,官方给的dome也都是安卓的,索性就自己改装一下,用uniapp做个简单的实现

// 依赖引入
const Intent = plus.android.importClass('android.content.Intent')
const IntentFilter = plus.android.importClass('android.content.IntentFilter')

const main = plus.android.runtimeMainActivity()
// pda定义的广播名称
const SCANACTION = "com.android.server.scannerservice.broadcast"

var filter = new IntentFilter()
filter.addAction(SCANACTION)

// 接收
var receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
    onReceive: onReceive
})
main.registerReceiver(receiver, filter)

function onReceive(context, intent) {
    if (intent.getAction() === SCANACTION) {
        const code = intent.getStringExtra("scannerdata");
        // 扫描信息处理
        uni.$emit('scan', code)
    }
}

以上为全部实现代码

你可能感兴趣的:(uni-app基于nativejs实现PDA手持终端扫码广播信息接收)