2 Replies Latest reply on Feb 20, 2018 4:53 AM by Prakhar Srivastava

    Issue in Broadcast Intent TC56 EMDK

    Prakhar Srivastava

      Hi,

      I tried to develop a sample application for scanner integration using EMDK broadcast intents.

      But when I scan, the onRecieve() is not getting called. I followed this tutorial : DataWedge Intent Example - Zebra Technologies TechDocs

       

      And Following is the code that I wrote:

       

      MainActivity.java

       

      package com.example.iwizards17.sample;

      import android.content.Intent;
      import android.content.IntentFilter;
      import android.os.Bundle;
      import android.support.v7.app.AppCompatActivity;
      import android.view.View;

      public class MainActivity extends AppCompatActivity{

       

         @Override
         protected void onCreate(Bundle savedInstanceState) {

         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);


         ScanBroadcastReceiver myBroadcastReceiver = new ScanBroadcastReceiver();
         IntentFilter filter = new IntentFilter();
         filter.addCategory(Intent.CATEGORY_DEFAULT);
         filter.addAction(getResources().getString(R.string.activity_intent_filter_action));
         registerReceiver(myBroadcastReceiver, filter);
         }

      }

       

       

       

      The ScanBroadcastReceiver

       

      package com.example.iwizards17.sample;

      import android.content.BroadcastReceiver;
      import android.content.Context;
      import android.content.Intent;
      import android.os.Bundle;


      public class ScanBroadcastReceiver extends BroadcastReceiver {

         @Override
         public void onReceive(Context context, Intent intent) {

        String action = intent.getAction();
         Bundle b = intent.getExtras();
        if (action.equals(context.getResources().getString(R.string.activity_intent_filter_action))) {

         // Received a barcode scan
         try {

        displayScanResult(context,intent, "via Broadcast");
         } catch (Exception e) {

         // Catch if the UI does not exist when we receive the broadcast... this is not designed to be a production app
         }

        }

        }

       

         private void displayScanResult(Context context, Intent initiatingIntent, String howDataReceived)

        {

        String decodedSource = initiatingIntent.getStringExtra(context.getResources().getString(R.string.datawedge_intent_key_source));
         String decodedData = initiatingIntent.getStringExtra(context.getResources().getString(R.string.datawedge_intent_key_data));
         String decodedLabelType = initiatingIntent.getStringExtra(context.getResources().getString(R.string.datawedge_intent_key_label_type));

        if (null == decodedSource)

        {

        decodedSource = initiatingIntent.getStringExtra(context.getResources().getString(R.string.datawedge_intent_key_source_legacy));
         decodedData = initiatingIntent.getStringExtra(context.getResources().getString(R.string.datawedge_intent_key_data_legacy));
         decodedLabelType = initiatingIntent.getStringExtra(context.getResources().getString(R.string.datawedge_intent_key_label_type_legacy));
         }

       

        }

      }

       

       

      Strings.xml

       

      <resources>
        <string name="app_name">SAMPLE</string>
        <string name="activity_intent_filter_action">app.iwiz.ACTION</string>
        <string name="datawedge_intent_key_source">com.symbol.datawedge.source</string>
        <string name="datawedge_intent_key_label_type">com.symbol.datawedge.label_type</string>
        <string name="datawedge_intent_key_data">com.symbol.datawedge.data_string</string>
        <string name="datawedge_intent_key_source_legacy">com.motorolasolutions.emdk.datawedge.source</string>
        <string name="datawedge_intent_key_label_type_legacy">com.motorolasolutions.emdk.datawedge.label_type</string>
        <string name="datawedge_intent_key_data_legacy">com.motorolasolutions.emdk.datawedge.data_string</string>
      </resources>

       

       

       

      My Build.gradle(just want to be sure, i am using the library correctly)

      Properties properties = new Properties()

      properties.load(project.rootProject.file('local.properties').newDataInputStream())

      def sdkDir = properties.getProperty('sdk.dir')

      provided fileTree(include: ['com.symbol.emdk.jar'], dir: sdkDir + '/add-ons/addon-symbol_emdk-symbol-23/libs/')

       

       

      And My Profile settings in DataWedge

      I have attached the Screenshots for same.

       

      When it didn't work, I tried registering it from the manifest also.

      <receiver android:name=".ScanBroadcastReceiver">
        <intent-filter>
        <action android:name="app.iwiz.ACTION" />
        </intent-filter>
      </receiver>