Enumerate Scanners

DataWedge 6.3

ENUMERATE_SCANNERS

Introduced in DataWedge 6.3.

Generates a numbered list (index) of scanners available on the device.

IMPORTANT: The scanner index is not fixed for all devices. It varies depending on the number of supported internal and/or external scanners installed and/or connected to the device at the time the index is generated.

Function Prototype

Intent i = new Intent();
i.setAction("com.symbol.datawedge.api.ACTION");
i.putExtra("com.symbol.datawedge.api.ENUMERATE_SCANNERS", "");

Parameters

ACTION [String]: "com.symbol.datawedge.api.ENUMERATE_SCANNERS"

Return Values

The enumerated list of scanners is returned via the broadcast intent com.symbol.datawedge.api.ACTION_ENUMERATEDSCANNERLIST. The list of scanners is returned as a string array (see example below).

Error and debug messages are logged to the Android logging system, which can be viewed and filtered by the logcat command. Use logcat from an ADB shell to view the log messages:


$ adb logcat -s DWAPI

Error messages are logged for invalid actions and parameters.

Example

// First send the intents to enumerate the available scanners on the device:
i.setAction("com.symbol.datawedge.api.ACTION");
i.putExtra("com.symbol.datawedge.api.ENUMERATE_SCANNERS", "");
this.sendBroadcast(i);

// define action string:
String enumerateScanners = "com.symbol.datawedge.api.ACTION";

// create the intent:
Intent i = new Intent();

// set the action to perform:
i.setAction(enumerateScanners);

// send the intent to DataWedge:
context.this.sendBroadcast(i);

// enable the app to receive the enumerated list of available scanners:
String enumeratedList = "com.symbol.datawedge.api.ACTION";

// create a filter for the broadcast intent
IntentFilter filter = new IntentFilter();
    filter.addAction(enumeratedList);
    filter.addCategory(Intent.CATEGORY_DEFAULT);  // NOTE: REQUIRED for DW6.2 and higher
    registerReceiver(myBroadcastReceiver, filter);

// create a broadcast receiver
private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() {
   @Override
   public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d(TAG, "Action: " + action); 

         if(action.equals("com.symbol.datawedge.api.RESULT_ACTION")){
            Bundle b = intent.getExtras();

// enumerate scanners
if(intent.hasExtra("com.symbol.datawedge.api.RESULT_ENUMERATE_SCANNERS")) {
    ArrayList<Bundle> scannerList = (ArrayList<Bundle>) intent.getSerializableExtra("com.symbol.datawedge.api.RESULT_ENUMERATE_SCANNERS");
if((scannerList != null) && (scannerList.size() > 0)) {
    for ( Bundle bunb: scannerList)
        Log.d(TAG,"Scanner:"+bunb.getString("SCANNER_NAME")+" Connection:"+bunb.getBoolean("SCANNER_CONNECTION_STATE")+" Index:"+bunb.getInt("SCANNER_INDEX"));
                }
            }
        }
    }
};

Comments

The scanner and its parameters are set based on the currently active Profile.


SEE ALSO:

Zebra Support Central | Integrator Guides, Product Manuals, Software Downloads and Support

LaunchPad | Zebra Developer Community

Intent | Android Developers

Intents and Intent Filters | Android Developers

Android Intents | Tutorial