Update - March 2018
This blog received an overhaul in March 2018 to update the APIs being used and rework the demo application to provide more up to date functionality.
DataWedge Intent Interface
DataWedge is a value-add of all Zebra Technologies devices (formally Symbol and Motorola Solutions) that allows barcode capture and configuration without the need to write any code. This application will demonstrate how to use Android intents to add DataWedge scanning functionality to your application
Quick Start - Getting the demo running
This application will demonstrate how to scan barcodes and control Datawedge from a Cordova based application.
>cordova platform add android
Plug in Zebra device Follow instructions under "Configuring Datawedge" (below)
>cordova run android --device
Scan a barcode
If your device supports Datawedge 6.3 or below you will need to complete additional setup, see the Configuring Datawedge section.
This section walks through the steps to create a new Cordova based application that utilises DataWedge for scanning.
Create a cordova application that will run on Android
cordova create DataWedgeCordova com.mycompany.datawedgecordova DataWedgeCordova
cordova platform add android
We will use a 3rd party plugin to handle sending and receiving Intents to the DataWedge service. Any plugin capable of sending or receiving generic intents and interpreting the extra bundle into JSON will work:
cordova plugin add https://github.com/darryncampbell/darryncampbell-cordova-plugin-intent.git
Note that a previous version of this blog used different 3rd party plugins which have since been deprecated. I wrote my own generic plugin to handle intents and released it under MIT to aid customers who wish to integrate DataWedge and Cordova but this should not be considered supported software by Zebra Technologies.
If your device is running Datawedge 6.4 or higher and you just want to run the demo application you can safely skip this section as the demo app will configure the Datawedge profile automatically.
DataWedge can be configured to send intents whenever it scans barcodes, there are more sophisticated ways to configure DataWedge but this section will cover the basics. More detailed help is available at the official documentation .
- Create a new DataWedge profile (Applications --> DataWedge --> Menu --> New Profile). This will be the profile that will be active when our Cordova application is in the foreground. Give it a name e.g. DataWedgeCordova and click into it to configure.
- The next step requires our Cordova application to have previously run on the device so if you have not already done so:
cordova run android
- Back in DataWedge configuration associate the Cordova application with our DW profile
- Scroll down to the Intent Output section of DW configuration and enable intents:
- Intent Action: com.zebra.cordovademo.ACTION (Note: This action changed with the update to this blog in March 2018)
- Intent Category: leave blank
- Intent delivery: Broadcast intent
Adding code to the Cordova application
Some example code from the demo application
Listening for intents
Since in the previous section DataWedge was configured to send barcode data to our application via an implicit broadcast intent we can use the 3rd party plugin to register a broadcast receiver:
'com.zebra.cordovademo.ACTION', // Scans
'com.symbol.datawedge.api.RESULT_ACTION' // Messages from service
// Broadcast received
console.log('Received Intent: ' + JSON.stringify(intent.extras));
if (intent.extras["com.symbol.datawedge.data_string"] != null)
console.log("Scan: " + intent.extras["com.symbol.datawedge.data_string"]);
DataWedge supports an intent based API documented here. The API supports many functions, code is shown here to initiate a scan without pressing the hardware key but the full demo also shows modifying the enabled decoders and retrieving Datawedge state:
To simulate a trigger press:
'com.symbol.datawedge.api.SOFT_SCAN_TRIGGER': 'TOGGLE_SCANNING' }
Now deploy & launch your app. You are able to scan barcodes and exercise the functionality:
The demo application is available from github: GitHub - darryncampbell/DataWedgeCordova: Cordova application using DataWedge solely through Intents
This technique for adding scanning capabilities to a Cordova application represents the most generic possible solution. We appreciate your developer feedback:
- Would you like to access EMDK profile functionality through Cordova?
Please feel free to raise github issues on the repository or post comments to this blog.