无法获取通知表单扫描仪

Unable to get Notification form Scanner

我正在为使用 DataWedge 的 Zebra Technologies TC8000 扫描仪开发一个应用程序。我正在为移动框架使用 Android Studio 3.5 和 flutter。

我在主 activity 中使用广播接收器并尝试在我的 Dart 代码中使用回调。

当我在扫描仪上扣动扳机时,我在 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

扫描光束亮起,扫描仪确认条形码已读取,但我没有收到事件。我很担心这条线:

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])

我查看了 Zebra 的文档并修改了我的代码以注册广播接收器。这是我的 MainActivity 代码:

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");
    }
}

这令人沮丧。这个问题似乎不在我的代码中,因为我在 onReceive() 事件中设置了断点并且该方法没有触发。

不确定是什么问题。

NOTIFICATION_ACTION仅用于通知您的应用程序扫描仪光束正在扫描、空闲等,它实际上不包含任何扫描数据。我认为您将 DataWedge API 与 DataWedge Intent Output 插件混淆了,我没有 Flutter 示例,但请看一下我在从 DataWedge 接收扫描数据时所做的快速 Java 教程: http://www.darryncampbell.co.uk/2017/12/13/tutorial-scan-with-datawedge-intent-output-on-zebra-devices/

我很确定关于 NotificationService 的错误与扫描器无关。

您的日志还表明您正在使用 Profile0(默认),这与我在教程中显示的相同,但您可能需要考虑为您的应用程序创建一个专用的配置文件。