Multiple Activities in Java

Demonstrates how to receive scanned barcode data through an Android intent while managing multiple activities.

Download Source

Product

DataWedge - 15.0

Devices

All supported Zebra Android 7 or higher devices

Overview

The MultiActivity sample app demonstrates how to receive scanned barcode data through an Android intent while handling multiple activities. It configures DataWedge, changes scanner hardware at runtime, modifies scanner parameters at runtime, registers for scanner status notifications, and uses the software scan trigger via DataWedge Intent APIs.

Key features of this sample:

  • Check if DataWedge is ready before sending any configurations
  • Create a profile if it does not exist
  • Set configurations for the profile
  • Switch profiles at runtime
  • Handle intent API calls in a multi-threaded environment
  • Enable/Disable scanner at runtime
  • Switch the scanner at runtime
  • Enable/Disable certain configurations at runtime
  • Toggle the software scan trigger
  • Register for scanner status notifications, such as waiting, scanning, etc.
  • Display the following for each decoded barcode:
    • Scan data
    • Decoder type

Requirements

  • This sample is developed for DataWedge 15.0 or later, though it may be compatible with earlier versions. Consult the DataWedge API documentation for any variations that may impact functionality.
  • Android 7 (Nougat) or higher

APIs Used

DataWedge API App Functionality
Get DataWedge Status Check whether DataWedge is enabled or disabled.
Create Profile Create a new profile without setting configurations.
Set Config Create or reset the profile for application requirements.
Register for status notifications Register to receive notifications via intent for scanner status changes.
Soft Scan Trigger Control scanning via soft scan trigger button.
Enable/Disable Scanner Input Plug-in Enable/Disable the Scanner Input Plug-in in use by the current active profile, which effectively disables scanning
Switch Scanner Params Temporarily update the settings of the active profile during runtime by passing scanner reader parameters as intent extras.
Enumerate Scanners Generate an index of scanners available on the device.
Switch Scanner Switch to a specific scanner at runtime to enable an optimal scanning device for the app, requirement or situation.
Switch to Profile Change the app association to the specified profile.

Using This Sample

  1. Download and build the sample app.

  2. Copy and launch the sample app on the device. The first activity appears, displaying the scanner status and active profile.

    • The DataWedge profile “MultiActivityProfile_1” is created and associated with this sample app.
    • Ensure DataWedge is enabled; the app will not function if it is disabled. If disabled, enable DataWedge and restart the app.
  3. Press the physical trigger button or toggle the soft scan button to perform a scan. The barcode data and symbology is displayed. Tap Next to proceed to the next activity.

  4. In this next activity, the app automatically attempts to switch to the associated profile, “MultiActivityProfile_2,” by invoking the Switch to Profile API. By default, the scanner is disabled.

    • If the profile switch fails, the app will create the relevant profile and then switch to it.

  5. Toggle Enable/Disable Scanner to activate it.

  6. Press the physical trigger button or toggle the soft scan button to perform a scan. The barcode data and symbology is displayed.

  7. Options:

    • Decode Screen Notification - When enabled, the app screen turns green briefly upon a successful decode.
    • Picklist - When enabled, targets scanning a specific barcode within the crosshair when multiple barcodes are present. This feature is applicable only to barcode imagers.

    Note: If the "Scanner status" is DISABLED, both options reset to their default state (disabled).

  8. Press the physical trigger button or toggle the soft scan button to perform a scan. The scanned data is displayed. If Decode Screen Notification is enabled, the screen turns green briefly upon a successful decode.

  9. (Optional) Use the DW Scanner dropdown to change the scanner hardware, if needed.


Related guides: