DataWedge on Android has the ability to output captured data via Intents. This article describes how to use the DataWedge Intent output plug-in and the Data Capture API to receive captured data in your native Android application.
For this tutorial we created an Android application with a blank activity, to which we added the following layout.
The things to note in the above layout are the ImageView and the EditText widgets. The ImageView widget will effectively act as a button which can be used to toggle the scanner instead of pressing the trigger button on the device. The EditText widget will be used to display the data that we receive in the intent.
The intent we will receive from DataWedge will contain a bundle of data which we will be retrieving using the Intent.getStringtExtra() and Intent.getSerializableExtra() methods.
The following is a list of the data item names that the bundle could contain.
String contains the output data as a String. In the case of concatenated bar codes, the decode data is concatenated and sent out as a single string. In the case of MSR output, the data from the MSR tracks is concatenated and sent out as a single string.
String contains the label type of the bar code.
Decode data returned as a list of byte arrays. In most cases there will be one byte array per decode. For bar-code symbologies that support concatenation e.g. Codabar, Code128, MicroPDF, etc., the decoded data is stored in multiple byte arrays (one byte array per bar code). Clients can get data in each byte array by passing an index.
The data from the MSR tracks is concatenated and sent out as a byte array.
MSR track 1 data is returned as a byte array.
MSR track 2 data is returned as a byte array.
MSR track 3 data is returned as a byte array.
MSR track 1 decode status as an Integer where 0 indicates a successful decode.
MSR track 2 decode status as an Integer where 0 indicates a successful decode.
MSR track 3 decode status as an Integer where 0 indicates a successful decode.
MSR track 1 encrypted data is returned as a byte array.
MSR track 2 encrypted data is returned as a byte array.
MSR track 3 encrypted data is returned as a byte array.
MSR track 1 hashed data is returned as a byte array.
MSR track 2 hashed data is returned as a byte array.
MSR track 3 hashed data is returned as a byte array.
This is the intent action for the soft scan trigger.
In the code that follows we will just be using the SOURCE_TAG, DATA_STRING_TAG and LABEL_TYPE_TAG intent data to display the intent data in the EditText widget.
Incoming intents can be handled by overriding the onNewIntent method.
Our activity layout has an ImageView which we will use as a button to toggle the scan trigger. This is done by using the Data Capture API. The following code toggles the scan trigger each time the image is tapped.
Let's put all that code together so that we can see what our final activity class should look like.
Having dealt with the coding of our activity, we now need to inform the system which implicit intents our application can handle. For that we need to define an intent-filter as follows.
We will be using the com.motorolasolutions.emdk.sample.dwdemosample.RECVR action and the android.intent.category.DEFAULT category we have just defined above later on when we come to configure our DataWedge profile.
In this article DataWedge is configured to use the startActivity() method to send the intent. The startActivity() method causes a new activity to be launched. However since we do not want another instance of our activity launched each time we receive an intent, we need to specify the launch mode of our activity as single task. android:launchMode="singleTask"
Now we need to configure DataWedge to send the desired intent to our application.
Create a new profile and give it a name such as "dwdemosample"
Download the source for this project in the associated sample.