Using Intent Output With DataCapture Profiles

EMDK For Android 4.0

Developing an EMDK for Android Application Part 2

This tutorial will walk you through adding Intent Output support to the EMDK For Android application you made using Developing an EMDK for Android Application Part 1. This tutorial will assume your project is at the state of the end of that tutorial and build on top of it. You can follow the tutorial in the previous step of download the source from the previous step and start from there.

The tutorial uses EMDK V 2.1 that has organized existing features as well as got some new features that would be discussed later in the tutorial.

Prerequisites

Adding Intents to the DataCapture Profile

  1. Select "EMDKSample" project from Package Explorer.

  2. Click "EMDK" menu present on the top-bar and select "Profile Manager" option.

  3. The EMDK Profile Manager Window will appear.

    img

  4. select "DataCaptureProfile" and click "Edit".

  5. Select "Intent" from the list of "Available Features" and add it to "Selected Features" by clicking "Right Arrow".

    Note: The field "Name" contains user defined name to identify a particular Intent Output feature. This is required when editing any specific Intent Output feature programmatically, which is outside the scope of this tutorial. So we will keep the "Name" field empty.

    img

  6. Select "Intent" from the list of "Selected Features".

  7. Now we will configure the "Intent" parameters.

    • Switch "Intent Output Enable" to Enable".
    • For "Intent Output Action" enter "com.symbol.emdksample.RECVR".
    • For "Intent Output Category" enter "android.intent.category.DEFAULT".
    • Switch "Intent Output Delivery" to "Send via startActivity".
    • Switch "Basic data formatting Enable" to Enable".
    • Switch "Basic data formatting Send Data" to Enable".

    Your Intent configuration should now look like this:

    img

  8. Click "Apply" and "Finish".

    img

  9. Click "Close".
    >Note:
    >Now the "EMDKConfig.xml" under "\assets" folder will be updated with your changes.

Adding the Intent Filter

  1. Open your application's "Manifest.xml" file.

    img

  2. Make the following changes to your application's"Manifest.xml" file.

    Add the following parameter to your activity settings to enable "singleTask" mode.

    
    android:launchMode="singleTask"  
    

    Add the following lines to receive EMDK Intents in your application:

    
    <intent-filter>  
            <action android:name="com.symbol.emdksample.RECVR"/>  
            <category android:name="android.intent.category.DEFAULT"/>  
    </intent-filter>     
    

    When done, your manifest.xml should look like this:

    img

    Note:

    • The intent action name should match the value of "Intent Output Action" in the EMDK Profile Manager.
    • The intent category name should match the value of "Intent Output Category" in the EMDK Profile Manager.

Adding the Intent code

  1. Add the following imports to your program.

    
    import android.content.Intent;  
    import android.widget.TextView; 
    

    img

  2. Add the following function to your program for processing intents.

    
    //This function is responsible for getting the data from the intent  
    private void handleDecodeData(Intent i)  
    {  
    
    }
    

    img

  3. Add the following code to your "onCreate" function check for a possible intent;

    
    //In case we have been launched by the DataWedge intent plug-in  
    Intent i = getIntent();  
    handleDecodeData(i); 
    

    img

  4. Overide "onNewIntent" to handle incoming intents.

    
    //We need to handle any incoming intents, so let override the onNewIntent method  
    @Override  
    public void onNewIntent(Intent i) {  
            handleDecodeData(i);  
    
    } 
    

    img

  5. Add a TextView in the UI called "textViewBarcode", inside "res/layout/activity_main.xml".

    
    <TextView  
            android:id="@+id/textViewBarcode"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_alignParentTop="true"  
        android:layout_centerHorizontal="true"  
        android:layout_marginTop="50dp"  
        android:text="@+string/hello_world"  
        android:textAppearance="?android:attr/textAppearanceMedium" />  
    

    img

  6. Add a global variable for the TextView.

    
    //Declare a variable to store the textViewBarcode  
    private TextView textViewBarcode = null;
    

    img

  7. Add the following code to your onCreate function to get a handle on the TextView.

    
    //Get the textViewBarcode  
    textViewBarcode = (TextView) findViewById(R.id.textViewBarcode); 
    

    img

  8. Add the following code to your "handleDecodeData" function to confirm the intent was meant for us.

    
    //Check the intent action is for us  
    if (i.getAction().contentEquals("com.symbol.emdksample.RECVR") ) {  
    
    } 
    

    img

  9. Add the following code to your "handleDecodeData" function to check if the intent contains Barcode data.

    
    //Get the source of the data  
    String source = i.getStringExtra("com.motorolasolutions.emdk.datawedge.source");  
    
    //Check if the data has come from the Barcode scanner  
    if(source.equalsIgnoreCase("scanner"))  
    {  
    
    }
    

    img

  10. Add the following code to your "handleDecodeData" function to retrieve Barcode data.

    
    //Get the data from the intent  
    String data = i.getStringExtra("com.motorolasolutions.emdk.datawedge.data_string");  
    
    //Check that we have received data  
    if(data != null && data.length() > 0)  
    {  
    
    } 
    

    img

  11. Add the following code to your "handleDecodeData" function to populate the TextView with the revived Barcode data.

    
    //Display the data to the text view  
    textViewBarcode.setText("Data = " + data); 
    

    img

  12. Connect the device (having the latest EMDK runtime) to USB port.

    Note:
    Make sure the device is in USB debug.

  13. Run the application.

    img

  14. Press the trigger button and scan a Barcode.

  15. The scanned data will be populated in the Edit Text field Through the previous Keystroke Intent and will appear on the Text View using the new Datawedge Intent.

    img

What's Next

The next tutorial will show you how to use multiple Data Capture Profiles that are handled by multiple activities.