mui实现新大陆PDA扫码接收

mui新大陆PDA实现扫码接收

通过广播的方式进行扫描结果的接收。通过native.js使用原生安卓类库

		mui.plusReady(function() {
     
				mui.init();
				 setTimeout(function() {
     
				 	scan(function(code) {
     
				 		console.log('扫描结果:' + code);
				 		GetUpperShelfApp(code);
				 	})
				 }, 10)
				if(mui.os.android) {
     
					var nativeWebview = plus.webview.currentWebview().nativeInstanceObject();
					plus.android.importClass(nativeWebview);
					nativeWebview.requestFocus();
				} else {
     
					alert(2);
					nativeWebview.plusCallMethod({
     
						"setKeyboardDisplayRequiresUserAction": false
					});
				}
		})

		function pageInit() {
     
				var _self = plus.webview.currentWebview()
				localStorage.setItem('WEBVIEW_ID', _self.id)
				mui.back = function() {
     
					localStorage.setItem('WEBVIEW_ID', _self.opener().id)
					_self.close();
				}
		}

			function scan(callback) {
     
				var main = plus.android.runtimeMainActivity(); //获取activity
				var receiver = plus.android.implements('io.dcloud.feature.internal.reflect.BroadcastReceiver', {
     
					onReceive: function(context, intent) {
      //实现onReceiver回调函数
						callback(intent.getStringExtra('SCAN_BARCODE1'))//SCAN_BARCODE1为条码1Extra
					}
				});
				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'); //广播输出action//监听扫码广播
				main.registerReceiver(receiver, filter); //注册监听
				mui.toast("初始化完成。");
			}

你可能感兴趣的:(mui,native,app)