Multiple Fragments in Java

Demonstrates how to receive scanned barcode data through an Android intent while handling a single activity with multiple fragments.

Download Source

Product

DataWedge - 15.0

Devices

All supported Zebra Android 7 or higher devices

Overview

The MultiFragment sample app demonstrates how to receive scanned barcode data through an Android intent while handling a single activity with multiple fragments. It configures DataWedge, adjusts 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
  • Handle intent API calls in a multi-threaded environment
  • Switch the scanner
  • 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.
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.

Using This Sample

  1. Download and build the sample app.

  2. Copy and launch the sample app on the device.

    • The DataWedge profile “MultiFragmentProfile” 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. The first fragment appears, displaying the scanner status and active profile.

  4. 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 go to the next fragment.

  5. The second fragment is displayed, using the same “MultiFragmentProfile” profile with the scanner initially disabled. Use Enable/Disable Scanner toggle to activate it.

  6. The scanner status updates to "Waiting." Press the physical trigger button or toggle the soft scan button to perform a scan.

  7. The barcode data and symbology is displayed for the scanned barcode.

  8. 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.

    Tap Update to apply these changes, which invokes the Switch Scanner Params API.

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

  9. 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.

  10. (Optional) Use the Switch Scanner dropdown to change the scanner hardware, if desired.


Related guides: