123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <template>
- <view class="content"></view>
- </template>
-
- <script>
- export default {
- data() {
- return {
- activity: null,
- receiver: null,
- intentFilter: null
- }
- },
- created: function(option) {
- this.initScan()
- this.startScan();
- },
- onHide: function() {
- this.stopScan();
- },
- destroyed: function() {
-
- this.stopScan();
- },
- methods: {
- initScan() {
- let _this = this;
-
- this.activity = plus.android.runtimeMainActivity();
- var context = plus.android.importClass('android.content.Context');
- var IntentFilter = plus.android.importClass('android.content.IntentFilter');
- this.intentFilter = new IntentFilter();
- this.intentFilter.addAction('nlscan.action.SCANNER_RESULT')
- this.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)
- }
- });
-
- },
- startScan() {
-
- this.activity.registerReceiver(this.receiver, this.intentFilter);
-
- },
- stopScan() {
-
- this.activity.unregisterReceiver(this.receiver);
-
- }
- }
- }
- </script>
-
- <style>
- </style>
|