I'd like to be able to broadcast to Datawedge to turn scanner on or off. For example, once a user scans a product, I'd request the scanner to be turned off until a quantity has been entered.
Here's a link from Zebra on how to do it. It just needs to be programmed into retool as command that can be executed after an activity.
Enable / Disable:
Enable / Disable can be called at any time
Intent dwIntent = new Intent();
dwIntent.setAction("com.symbol.datawedge.api.ACTION");
// Enable
dwIntent.putExtra("com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN", "ENABLE_PLUGIN");
// or Disable
dwIntent.putExtra("com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN", "DISABLE_PLUGIN");
sendBroadcast(dwIntent);
Resume / Suspend:
Resume / Suspend is much quicker but Suspend can only be called when the scanner is in the SCANNING
or WAITING
state
Intent dwIntent = new Intent();
dwIntent.setAction("com.symbol.datawedge.api.ACTION");
// Resume
dwIntent.putExtra("com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN", "RESUME_PLUGIN");
// or Suspend
if (okToSuspend)
dwIntent.putExtra("com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN", "SUSPEND_PLUGIN");
sendBroadcast(dwIntent);
You can determine the scanner state using the GetScannerStatus or RegisterForNotification APIs:
// RegisterForNotification
@Override
protected void onResume()
{
super.onResume();
IntentFilter filter = new IntentFilter();
filter.addAction("com.symbol.datawedge.api.NOTIFICATION_ACTION");
filter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(myBroadcastReceiver, filter);
}
private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals("com.symbol.datawedge.api.NOTIFICATION_ACTION"))
{
if (intent.hasExtra("com.symbol.datawedge.api.NOTIFICATION"))
{
Bundle extras = intent.getBundleExtra("com.symbol.datawedge.api.NOTIFICATION");
String notificationType = extras.getString("NOTIFICATION_TYPE");
if (notificationType != null && notificationType.equals("SCANNER_STATUS"))
{
// We have received a change in Scanner status
String scannerStatus = extras.getString("STATUS");
if (scannerStatus.equals("WAITING") || scannerStatus.equals("SCANNING"))
okToSuspend = true;
else
okToSuspend = false;
}
}
}
}
};