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 :/