Saya sedang mengerjakan aplikasi untuk pemindai Zebra Technologies TC8000 menggunakan DataWedge. Saya menggunakan Android Studio 3.5 dan bergetar untuk kerangka kerja seluler.

Saya menggunakan Penerima Siaran dalam aktivitas utama saya dan mencoba menggunakan panggilan balik dalam kode Dart saya.

Ketika saya menarik pelatuk pada pemindai, saya melihat yang berikut di logcat:

04-22 11:35:12.946 1009-1009/? D/ScannerPlugin: Scan status changed from SCAN_STATUS_WAITFORTRIGGER to SCAN_STATUS_SCANNING
04-22 11:35:12.946 1009-1009/? D/Client: requested to send: 110 (ScannerStateChanged): SCAN_STATUS_SCANNING
04-22 11:35:12.956 1009-1009/? D/Client: sent: 110 (ScannerStateChanged): SCAN_STATUS_SCANNING
04-22 11:35:12.956 1009-1009/? D/ScannerPlugin: Status:SCANNING;ProfileName:Profile0 (default)
04-22 11:35:12.956 1009-1009/? D/ScannerStateChanged: deserialize: state: SCAN_STATUS_SCANNING
04-22 11:35:12.966 1009-1009/? D/Protocol: parsed 110 (ScannerStateChanged): SCAN_STATUS_SCANNING
04-22 11:35:12.966 1009-1009/? D/SwipeAssistService: handleMessage(110 (ScannerStateChanged): SCAN_STATUS_SCANNING), connected clients: 1
04-22 11:35:13.416 665-665/? E/NotificationService: Not posting notification with icon==0: Notification(pri=0 contentView=com.symbol.datawedge/0x1090064 vibrate=null sound=null defaults=0x0 flags=0x11 kind=[null])
04-22 11:35:13.416 665-665/? E/NotificationService: WARNING: In a future release this will crash the app: com.symbol.datawedge
04-22 11:35:13.436 1009-1009/? D/ScannerPlugin: Scan status changed from SCAN_STATUS_SCANNING to SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/Client: requested to send: 110 (ScannerStateChanged): SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/Client: sent: 110 (ScannerStateChanged): SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/ScannerPlugin: Status:WAITING;ProfileName:Profile0 (default)
04-22 11:35:13.436 1009-1009/? D/ScannerStateChanged: deserialize: state: SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/Protocol: parsed 110 (ScannerStateChanged): SCAN_STATUS_WAITFORTRIGGER
04-22 11:35:13.436 1009-1009/? D/SwipeAssistService: handleMessage(110 (ScannerStateChanged): SCAN_STATUS_WAITFORTRIGGER), connected clients: 1

Sinar pindai menyala dan pemindai mengakui kode batang telah dibaca, tetapi saya tidak menerima acara tersebut. Saya khawatir tentang garis:

04-22 11:35:13.416 665-665/? E/NotificationService: Not posting notification with icon==0: Notification(pri=0 contentView=com.symbol.datawedge/0x1090064 vibrate=null sound=null defaults=0x0 flags=0x11 kind=[null])

Saya telah memeriksa dokumen Zebra dan memodifikasi kode saya untuk mendaftarkan penerima siaran. Ini kode MainActivity saya:

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;


import com.goodyear.flutter_plugin.R;

import static android.content.ContentValues.TAG;

public class MainActivity extends FlutterActivity {

    private static String INTENT_ACTION;
    private static String SCAN_DATA;

    private static String CHANNEL;
    private static String METHOD;
    private static String NOTIFICATION_ACTION;
    private static String NOTIFICATION_TYPE_SCANNER_STATUS;

    private Result barcodeResult;

    private void registerReceivers() {
        IntentFilter filter = new IntentFilter();
        filter.addAction(NOTIFICATION_ACTION);
        registerReceiver(broadcastReceiver, filter);
    }

    private void unRegisterReceivers() {
        unregisterReceiver(broadcastReceiver);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.i("Barcode", "Inside onCreate");
        super.onCreate(savedInstanceState);

        INTENT_ACTION = getResources().getString(R.string.activity_intent_filter_action);
        SCAN_DATA = getResources().getString(R.string.datawedge_intent_key_data);

        CHANNEL = getResources().getString(R.string.barcode_method_channel);
        METHOD = getResources().getString(R.string.barcode_method);

        NOTIFICATION_ACTION = getResources().getString(R.string.datawedge_notification_action);
        NOTIFICATION_TYPE_SCANNER_STATUS = getResources().getString(R.string.datawedge_notification_scanner_status);

        registerReceivers();

        Bundle b = new Bundle();
        b.putString("com.symbol.datawedge.api.APPLICATION_NAME", "com.example.intenttest");
        b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE", "SCANNER_STATUS");
        Intent i = new Intent();
        i.setAction("com.symbol.datawedge.api.ACTION");
        i.putExtra("com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION", b);//(1)
        this.sendBroadcast(i);

        new MethodChannel(getFlutterView(), CHANNEL).setMethodCallHandler(
                new MethodCallHandler() {
                    @Override
                    public void onMethodCall(MethodCall call, Result result) {
                        Log.i("Barcode", "Inside onMethodCall");

                        if (call.method.equals(METHOD)) {
                            Log.i("Barcode", "Result = " + result);
                            barcodeResult = result;
                        }

                        Log.i("Barcode", "Leaving onMethodCall");
                    }
                }
        );

        Log.i("Barcode", "Leaving onCreate");
    }

    @Override
    protected void onDestroy() {
        unRegisterReceivers();
        super.onDestroy();
    }

    private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.i("Barcode", "Inside onReceive");
            String action = intent.getAction();

            Log.d("Barcode", "#DataWedge-APP# Action: " + action);

            switch (action) {
                case "com.symbol.datawedge.api.NOTIFICATION_ACTION":
                    logStatus(intent);
                    break;
                case "com.com.goodyear.ACTION":
                    readScanData(intent);
                    break;
            }
        }
    };

    private void logStatus(Intent intent) {
        if (intent.hasExtra("com.symbol.datawedge.api.NOTIFICATION")) {
            Bundle b = intent.getBundleExtra("com.symbol.datawedge.api.NOTIFICATION");
            String NOTIFICATION_TYPE = b.getString("NOTIFICATION_TYPE");
            if (NOTIFICATION_TYPE != null) {
                Log.d("Barcode", "SCANNER_STATUS: status: " + b.getString("STATUS") + ", profileName: " + b.getString("PROFILE_NAME"));
            }
        }
    }

    private void readScanData(Intent intent) {
        String barCode = intent.getStringExtra(SCAN_DATA);
//            String decodedLabelType = intent.getStringExtra(getResources().getString(R.string.datawedge_intent_key_label_type));

        try {
            Log.i("Barcode", "Barcode = " + barCode);
            barcodeResult.success(barCode);
        } catch (Exception e) {
            //  Catch if the UI does not exist when we receive the broadcast
        }

        Log.i("Barcode", "Leaving onReceive");
    }
}

Ini membuat frustrasi. Masalahnya tampaknya tidak ada dalam kode saya karena saya telah menetapkan breakpoint di acara onReceive() dan metode itu tidak menyala.

Tidak yakin apa masalahnya.

1
Paul Stoner 20 September 2019, 23:20

1 menjawab

Jawaban Terbaik

NOTIFICATION_ACTION hanya digunakan untuk memberi tahu aplikasi Anda bahwa berkas pemindai sedang memindai, IDLE, dll., sebenarnya tidak berisi data pindaian apa pun. Saya pikir Anda membingungkan API DataWedge dengan plugin Output Intent DataWedge, saya tidak memiliki contoh Flutter tetapi silakan lihat tutorial Java cepat yang saya lakukan saat menerima data pindaian dari DataWedge: http://www.darryncampbell.co .uk/2017/12/13/tutorial-scan-with-datawedge-intent-output-on-zebra-devices/

Saya cukup yakin bahwa kesalahan tentang NotificationService tidak terkait dengan pemindai.

Log Anda juga menunjukkan bahwa Anda menggunakan Profile0 (default), yang sama dengan yang saya tunjukkan di tutorial tetapi Anda mungkin ingin mempertimbangkan untuk membuat Profil khusus untuk aplikasi Anda.

1
Darryn Campbell 22 September 2019, 19:47