1

I am creating an Android apk on ZEBRA MC3300 - this device have preinstalled DataWedge, in my app I use Zebra InputScannerPlugin to disable/enable scanner depending on activity. I have code for disable/enable methods from Zebra guide it looks like that:

    static String scannerInputPlugin = "com.symbol.datawedge.api.ACTION";
    static String extraData = "com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN";

public static void enableScanner(Activity activity){
        try {            
            if(!scannerEnabled) {
                Intent i = new Intent();
                i.setAction(scannerInputPlugin);
                i.putExtra(extraData, "ENABLE_PLUGIN");
                activity.sendBroadcast(i);
            }
            scannerEnabled = true;
        }catch(Exception e){
            Log.d("TERMINALPROP", e.toString());
        }
}
public static void disableScanner(Activity activity){
        try {            
            if(!scannerEnabled) {
                Intent i = new Intent();
                i.setAction(scannerInputPlugin);
                i.putExtra(extraData, "DISABLE_PLUGIN");
                activity.sendBroadcast(i);
            }
            scannerEnabled = true;
        }catch(Exception e){
            Log.d("TERMINALPROP", e.toString());
        }
}

I am using disableScanner and enableScanner at onResumie methods, and it works fine, but also I am using them at my AsyncTask at onPreExecute and onPostExecute methods.

Sometimes I got problem that my scanner do not react to enable/disable. It looks like datawedge runtime stops working, I send there broadcast and nothing changes - scanner stays disabled, but it not happens every time.

I was able to recreate problem several times. It looks like that:

I have Activity A and B. At activity A at method onResumie I am disabling scanner, before I start activity B, I am using AsyncTask (it disable on preExecute, and enable Scanner on postExecute), and I am switching to activity B and there onResume method I call enableScanner again.

And if I switch activities very fast, sometimes my scanner stays disabled, and stops react to all my enableScanner calls. It happens randomly, sometimes after 3 switches of activity, sometimes I have to switch it 20 times etc.

Any idea what I am doing wrong?

@EDIT It probably something with Datawedge InputScanner plugin - (I removed if(!scannerEnabled) from methods) and just added result codes to my apk, and when scanner is 'blocked' it returns me SCANNER_ALREADY_ENABLED when I call enableScanner but scanner is disabled :/

Delphi Coder
  • 1,723
  • 1
  • 14
  • 25
Cerveza
  • 11
  • 2
  • Have you checked the `Log.d("TERMINALPROP", e.toString());` `postExecute()` runs on UI thread but if the Activity is dead it will not work. `. The `Activity activity` context will not work if Activity is closed using back button – Erik Mar 15 '19 at 13:31
  • It probably something with Datawedge InputScanner plugin - (I removed if(!scannerEnabled) from methods) and just added result codes to my apk, and when scanner is 'blocked' it returns me SCANNER_ALREADY_ENABLED when I call enableScanner but scanner is disabled :/ – Cerveza Mar 15 '19 at 14:49

2 Answers2

0

If you never want the scanner to be enabled in Activity A then create a new DataWedge profile, associate it with Activity A and disable the barcode input plugin. You would have another profile associated with Activity B with the barcode input plugin enabled. You can then remove all the code logic around enabling / disabling the scanner when either activity gets focus as DataWedge will handle that automatically.

Darryn Campbell
  • 1,441
  • 10
  • 13
0

I have noticed the same behavior with DataWedge with small differences between versions.

  • 6.7 will totally stop sending broadcast events or notice the trigger button on my TC20.
  • 6.6 will only stop for a certain time. Also switching apps / activities might work.

I found out that (on 6.7.47 at least) the following looks to work;

Every time you want to enable the scanner to scan do:

  1. Use a profile linked with your whole app. (not only specific activities)
  2. Disable Datawegde by intent (and delay a little)
  3. Enable DataWedge by intent (and delay a little)
  4. Enable the scanner plugin by intent

With this approach my app will not end up with a disabled scanner.

Mark Ebbers
  • 187
  • 3
  • 13