uni-app 使用上海商睿pda调用 红外线扫码

let that = this
this.main_item = plus.android.runtimeMainActivity(); //获取activity    
var context = plus.android.importClass('android.content.Context'); //上下文    
this.receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
	onReceive: doReceive
});
var IntentFilter = plus.android.importClass('android.content.IntentFilter');
var Intent = plus.android.importClass('android.content.Intent');
var filter = new IntentFilter();
filter.addAction("android.scanner.scan"); //监听扫描    
this.main_item.registerReceiver(this.receiver, filter); //注册监听    
function doReceive(context, intent) {
	plus.android.importClass(intent);  
	var the_num = intent.getStringExtra("result");
	console.log(the_num);//返回数据
	that.main_item.unregisterReceiver(that.receiver);//解除广播
}

你可能感兴趣的:(uni-app,html5)