Register/Unregister for Notification

DataWedge 11.4

REGISTER_FOR_NOTIFICATION

Introduced in DataWedge 6.4. WORKFLOW_STATUS introduced in DataWedge 11.2.

Enable apps to register or unregister to receive notifications for status changes related to configuration, scanner, profile switching, Barcode Highlighting and Workflow Input. These status changes can result from DataWedge API calls (such as IMPORT_CONFIG, SWITCH_TO_PROFILE, and SCANNER_INPUT_PLUGIN) or DataWedge profile changes (such as profile Auto Import).

Function Prototype

Bundle b = new Bundle();
    b.putString("com.symbol.datawedge.api.APPLICATION_NAME","com.example.MyApp");
    b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE","PROFILE_SWITCH");
    Intent i = new Intent();
    i.setAction("com.symbol.datawedge.api.ACTION");
    i.putExtra("com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION", b);
    this.sendBroadcast(i);

Parameters

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

EXTRA_DATA [String]: "com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION"

BUNDLE:

  • APPLICATION_NAME - Package name of the app to register
  • NOTIFICATION_TYPE - Supported types:

Return Values

Returns a bundle with status of the requested DataWedge NOTIFICATION_TYPE

EXTRA NAME: "com.symbol.datawedge.api.NOTIFICATION"

BUNDLE:

  • CONFIGURATION_UPDATE [String]:
    • "PROFILE_IMPORTED" "FULL_DB_IMPORTED"
    • "PROFILE_NAME": "<Application package name>"
  • PROFILE_SWITCH:
    • "PROFILE_IMPORTED" "FULL_DB_IMPORTED"
    • "PROFILE_NAME": "<name of Profile now in use>"
  • SCANNER_STATUS:
    • WAITING - Scanner is enabled and ready to scan using a physical trigger or SOFT_SCAN_TRIGGER intent.
    • SCANNING - Scanner has emitted the scan beam and scanning is in progress. This event does not prevent the application from disabling other controls as necessary.
    • CONNECTED - A Bluetooth scanner has connected with the device and can now be enabled (or disabled) by the application. Scanner selection should be set to Auto in the currently active profile.
    • DISCONNECTED - A Bluetooth scanner has disconnected from the device. Sending an intent to enable or disable the scanner in this state will enable/disable the current default scanner.
    • IDLE - Scanner is in one of the following states: enabled but not yet in the waiting state, in the suspended state by an intent (e.g. SUSPEND_PLUGIN) or disabled due to the hardware trigger.
    • DISABLED - Scanner is disabled. This is broadcasted by the scanner plug-in when the active profile becomes disabled manually or the scanner is disabled with an intent (e.g. DISABLE_PLUGIN).
  • WORKFLOW_STATUS - "Workflow" refers to usage related to Workflow Input (e.g. scanning identification documents, reading license plates, etc.) or Barcode Highlighting:
    • PLUGIN_READY - Workflow Input plug-in or Barcode Highlighting is ready to scan. This state notifies the user that DataWedge is ready to accept Intent API calls related to Workflow Input. Any intent API calls sent to DataWedge before this state will encounter undefined behavior. When a device is rebooted, sometimes it may take few seconds to initialize Workflow Input.
    • DISABLED - Selected workflow is disabled. This is broadcasted by the Workflow Input plug-in when the active profile becomes disabled manually or the workflow is disabled with an intent.
    • WORKFLOW_READY - Workflow Input plug-in or Barcode Highlighting is enabled and the selected workflow is in the process of being enabled, but not fully enabled yet.
    • WORKFLOW_ENABLED - Workflow Input plug-in or Barcode Highlighting is enabled and the selected workflow is enabled, waiting for the session to start.
    • SESSION_STARTED - Workflow is ready and waiting for the user to press the trigger to scan.
    • CAPTURING_STARTED - Viewfinder has started - the user can place the subject in the field of view to capture data.
    • CAPTURING_STOPPED - Viewfinder has stopped and the status immediately returns to the SESSION_STARTED state.

Scanner status notifications are sent only if the scanner in the active Profile is enabled.

Note: The PROFILE_NAME (of the currently active profile) is returned with SCANNER_STATUS to allow the developer to filter scanner events for the required Profile only.

Example Code

void registerUnregister() {
    // TO REGISTER AN APP TO RECIEVE NOTIFICATIONS

    // Register for notifications - PROFILE_SWITCH
    Bundle b = new Bundle();
    b.putString("com.symbol.datawedge.api.APPLICATION_NAME", "com.example.intenttest");
    b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE", "PROFILE_SWITCH");
    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);


    // To unregister, change only the iPutExtra command
    Bundle b = new Bundle();
    b.putString("com.symbol.datawedge.api.APPLICATION_NAME", "com.example.intenttest");
    b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE", "PROFILE_SWITCH");
    Intent i = new Intent();
    i.setAction("com.symbol.datawedge.api.ACTION");
    i.putExtra("com.symbol.datawedge.api.UNREGISTER_FOR_NOTIFICATION", b);
    this.sendBroadcast(i);


    // Register for notifications - SCANNER_STATUS
    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);

    // To unregister, change only the iPutExtra command
    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.UNREGISTER_FOR_NOTIFICATION", b);
    this.sendBroadcast(i);

    // Register for notifications - WORKFLOW_STATUS
    Bundle b = new Bundle();
    b.putString("com.symbol.datawedge.api.APPLICATION_NAME", "com.example.intenttest");
    b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE", "WORKFLOW_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);

    // Unregister for notifications - WORKFLOW_STATUS
    Bundle b = new Bundle();
    b.putString("com.symbol.datawedge.api.APPLICATION_NAME", "com.example.intenttest");
    b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE", "WORKFLOW_STATUS");
    Intent i = new Intent();
    i.setAction("com.symbol.datawedge.api.ACTION");
    i.putExtra("com.symbol.datawedge.api.UNREGISTER_FOR_NOTIFICATION", b);
    this.sendBroadcast(i);

}

// TO RECIEVE NOTIFICATIONS
public static final String NOTIFICATION_ACTION = "com.symbol.datawedge.api.NOTIFICATION_ACTION";
public static final String NOTIFICATION_TYPE_SCANNER_STATUS = "SCANNER_STATUS";
public static final String NOTIFICATION_TYPE_PROFILE_SWITCH = "PROFILE_SWITCH";
public static final String NOTIFICATION_TYPE_WORKFLOW_STATUS = "WORKFLOW_STATUS";
public static final String NOTIFICATION_TYPE_CONFIGURATION_UPDATE = "CONFIGURATION_UPDATE";

private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        Log.d(TAG, "#DataWedge-APP# Action: " + action);

        if (action.equals(NOTIFICATION_ACTION)) {

            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) {
                    switch (NOTIFICATION_TYPE) {
                        case NOTIFICATION_TYPE_SCANNER_STATUS:
                            Log.d(TAG, "SCANNER_STATUS: status: " + b.getString("STATUS") + ", profileName: " + b.getString("PROFILE_NAME"));
                            break;

                        case NOTIFICATION_TYPE_PROFILE_SWITCH:
                            Log.d(TAG, "PROFILE_SWITCH: profileName: " + b.getString("PROFILE_NAME") + ", profileEnabled: " + b.getBoolean("PROFILE_ENABLED"));
                            break;

                        case NOTIFICATION_TYPE_CONFIGURATION_UPDATE:
                            break;
                        case NOTIFICATION_TYPE_WORKFLOW_STATUS:
                            Log.d(TAG, "WORKFLOW_STATUS: status: " + b.getString("STATUS") + ", profileName: " + b.getString("PROFILE_NAME"));
                            break;

                    }
                }
            }
        }
    }
};

void registerReceivers() {
    //to register the broadcast receiver
    IntentFilter filter = new IntentFilter();
    filter.addAction(NOTIFICATION_ACTION);
    registerReceiver(broadcastReceiver, filter);//Android method
}

void unRegisterReceivers() {
    //to unregister the broadcast receiver
    unregisterReceiver(broadcastReceiver); //Android method
}

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