集成新大陆、斑马PDA
代码如下:
document.addEventListener('plusready',function () {
scan(function(code) {
console.log('扫描结果:' code);
})
},false);
function scan(callback) {
var main = plus.android.runtimeMainActivity(); //获取activity
var context = plus.android.importClass('android.content.Context'); //上下文
var receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
onReceive: function(context, intent) { //实现onReceiver回调函数
var device_model = plus.device.model;
console.log(device_model);
if(device_model=="NLS-MT90"){
//新大陆 NLS-MT90
callback(intent.getStringExtra('SCAN_BARCODE1')) ;
}
if(device_model=="TC20"){
//斑马 TC20
callback(intent.getStringExtra('com.motorolasolutions.emdk.datawedge.data_string'));
}
}
});
var IntentFilter = plus.android.importClass('android.content.IntentFilter'); //引入过滤器
var Intent = plus.android.importClass('android.content.Intent');
var filter = new IntentFilter();
filter.addAction('nlscan.action.SCANNER_RESULT'); //新大陆广播
filter.addAction('com.zsscan.ACTION');//斑马广播:需要在DataWedge设置
main.registerReceiver(receiver, filter); //注册监听
mui.toast("初始化完成。");
}
斑马PDA需要在设备端配置DataWedge:
进入DataWedge,右上角新增配置文件启用Intent,关联应用程序处关联扫码的APP,Intent操作设置为com.zsscan.ACTION,Intent交付设置为广播Intent
原贴地址 https://blog.csdn.net/qq_37182421/article/details/116750530