Search code examples
javaandroidbarcode-scanner

Unable to get Notification form Scanner


I am working on an application for a Zebra Technologies TC8000 scanner using the DataWedge. I'm using Android Studio 3.5 and flutter for the mobile framework.

I am using a Broadcast Receiver in my main activity and attempting to use a call back in my Dart code.

When I pull the trigger on the scanner, I see the following in 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

The scan beam comes on and the scanner acknowledges the bar code read, but I'm not receiving the event. I'm concerned over the line:

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

I've checked Zebra's documents and modified my code to register the broadcast receiver. Here is my MainActivity code:

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

This is frustrating. The issue does not seem to be in my code as I have set breakpoints in the the onReceive() event and that method does not fire.

Not sure what the issue is.


Solution

  • NOTIFICATION_ACTION is only used to notify your application that the scanner beam is scanning, IDLE etc, it does not actually contain any scan data. I think you are confusing the DataWedge API with the DataWedge Intent Output plugin, I don't have a Flutter example but please take a look at a quick Java tutorial I did on receiving scan data from DataWedge: http://www.darryncampbell.co.uk/2017/12/13/tutorial-scan-with-datawedge-intent-output-on-zebra-devices/

    I am pretty sure that error about NotificationService is unrelated to the scanner.

    Your log also indicates that you are using Profile0 (default), which is the same I show in the tutorial but you may want to consider creating a dedicated Profile for your app.