Enabling and disabling the scanner and msr

My application has the need to enable and disable both the scanner and the msr at various points throughout a sequence of operations.  For example, there are situations where scanner input is allowed but MSR input is not.  My plan for implementing this behavior was to create a profile with characteristic type "MSR", emdk_name="theMsr"  that initially has msr_input_enabled set to false and a characteristic type "Barcode", emdk_name="theScanner" that has scanner_input_enabled also set to false.

 

Then at the appropriate type I call processProfileAsync with name/value pair as follows:

 

     to enable scanner: theScanner.scanner_input_enabled=true

     to disable scanner: theScanner.scanner_input_enabled=false

     to enable msr:theMsr.msr_input_enabled=true

     to disable msr: theMsr.msr_input_enabled=false

 

Every time I call processProfileAsync the onData callback indicates success but it does not work reliably.  Also, it seems to take upwards of one second to process the profile.  My application needs to be able to switch the scanner and msr off/on very quickly and this one second delay is causing me problems.

 

WRT to reliability:  It seems if you call processProfile twice in rapid succession there are problems.  If I try to enable both devices by clicking the checkboxes as fast as I can I only get one onData callback (shouldn't I be getting two? one for each processProfile call) and it is random whether both devices will be enabled.  Sometimes the scanner gets enabled sometimes the MSR.  Same with disabling.   the onData callback says the operation worked but the scanner is still enabled. 

 

I wrote a simple test program that has check boxes to enable and disable the devices.  What am I doing wrong?

Attached is project demonstrating the issues I'm seeing.  Inline are my main activity source and profile.

 

Thanks

 

 

Start MainActivity.java-----------------------------------------

package com.example.johnfoley.myapplication;

 

import android.app.Activity;

import android.content.Intent;

import android.os.Bundle;

import android.util.Log;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.CheckBox;

import android.widget.EditText;

 

import com.symbol.emdk.EMDKManager;

import com.symbol.emdk.EMDKManager.EMDKListener;

import com.symbol.emdk.EMDKResults;

import com.symbol.emdk.ProfileManager;

import com.symbol.emdk.payment.PaymentManager;

 

import static com.symbol.emdk.ProfileManager.CreateNameValuePair;

 

public class MainActivity extends Activity implements EMDKListener, ProfileManager.DataListener {

 

   private String profileName = "QVSProfile";

   private ProfileManager mProfileManager = null;

   private EMDKManager emdkManager = null;

 

 

   @Override
   protected void onCreate(Bundle savedInstanceState) {

   super.onCreate(savedInstanceState);

  setContentView(R.layout.activity_main);

   //The EMDKManager object will be created and returned in the callback.
   EMDKResults results = EMDKManager.getEMDKManager(getApplicationContext(), this);

 

   //Check the return status of getEMDKManager
   if (results.statusCode == EMDKResults.STATUS_CODE.FAILURE) {

  Log.d("", "getEMDKManager() failed");

  }

  }

 

   @Override
   public boolean onCreateOptionsMenu(Menu menu) {

   // Inflate the menu; this adds items to the action bar if it is present.
   getMenuInflater().inflate(R.menu.menu_main, menu);

   return true;

  }

 

   @Override
   public boolean onOptionsItemSelected(MenuItem item) {

   // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
   int id = item.getItemId();

 

   //noinspection SimplifiableIfStatement
   if (id == R.id.action_settings) {

   return true;

  }

 

   return super.onOptionsItemSelected(item);

  }

 

   @Override
   public void onOpened(EMDKManager emdkManager) {

   if (emdkManager != null) {

   //Get the ProfileManager object to process the profiles
   mProfileManager = (ProfileManager) emdkManager.getInstance(EMDKManager.FEATURE_TYPE.PROFILE);

 

   if (mProfileManager != null) {

   try {

   mProfileManager.addDataListener(this);

 

  EMDKResults results = mProfileManager.processProfileAsync(profileName, ProfileManager.PROFILE_FLAG.SET, (String[]) null);

   if (results.statusCode == EMDKResults.STATUS_CODE.FAILURE) {

  Log.d("", "processProfile() failed");

  }

  } catch (Exception ex) {

  Log.d("", "Exception in onOpened", ex);

  }

  }

  }

  }

 

   @Override
   public void onDestroy() {

   super.onDestroy();

   //Clean up the objects created by EMDK manager
   if (emdkManager != null)

   emdkManager.release();

  }

 

   @Override
   public void onClosed() {

  }

 

   public void onScannerEnabledClick(View view) {

   boolean checked = ((CheckBox) view).isChecked();

 

  String[] xtraData = new String[1];

  xtraData[0] = CreateNameValuePair("theScanner", "scanner_input_enabled", checked ? "true" : "false");

  EMDKResults results = mProfileManager.processProfileAsync(profileName, ProfileManager.PROFILE_FLAG.SET, xtraData);

 

  Log.d("","SCANCMD:" + xtraData[0]);

 

   if (results.statusCode == EMDKResults.STATUS_CODE.FAILURE) {

  Log.d("", "processProfile() scanner enable/disable failed");

  }

  }

 

   public void onMsrEnabledClick(View view) {

   boolean checked = ((CheckBox) view).isChecked();

 

  String[] xtraData = new String[1];

  xtraData[0] = CreateNameValuePair("theMsr", "msr_input_enabled", checked ? "true" : "false");

  EMDKResults results = mProfileManager.processProfileAsync(profileName, ProfileManager.PROFILE_FLAG.SET, xtraData);

 

  Log.d("","MSRCMD:" + xtraData[0]);

 

   if (results.statusCode == EMDKResults.STATUS_CODE.FAILURE) {

  Log.d("", "processProfile() msr enable/disable failed");

  }

  }

 

   @Override
   public void onData(ProfileManager.ResultData resultData) {

   if (resultData.getResult().statusCode == EMDKResults.STATUS_CODE.FAILURE) {

  Log.d("", "async process profile failed");

  } else {

  Log.d("", "async process profile succeeded");

  }

  }

 

   @Override
   public void onNewIntent(Intent i) {

  handleDecodeData(i);

  }

 

   private static final String SOURCE_TAG = "com.motorolasolutions.emdk.datawedge.source";

   private static final String DATA_STRING_TAG = "com.motorolasolutions.emdk.datawedge.data_string";

   private static final String LABEL_TYPE_TAG = "com.motorolasolutions.emdk.datawedge.label_type";

 

   private static int msrReadCount = 0;

 

   private void handleDecodeData(Intent i) {

   // check the intent action is for us
   if (i.getAction().contentEquals("com.example.johnfoley.myapplication.RECVR")) {

  String out = "";

   // get the source of the data
   String source = i.getStringExtra(SOURCE_TAG);

   // save it to use later
   if (source == null)

  source = "scanner";

 

 

  String data = i.getStringExtra(DATA_STRING_TAG);

 

 

  Integer data_len = 0;

   if (data != null)

  data_len = data.length();

 

   // check if the data has come from the barcode scanner
   if (source.equalsIgnoreCase("scanner")) {

   // check if there is anything in the data
   if (data != null && data.length() > 0) {

   // we have some data, so let's get it's symbology
   String sLabelType = i.getStringExtra(LABEL_TYPE_TAG);

   // check if the string is empty
   if (sLabelType != null && sLabelType.length() > 0) {

   // format of the label type string is LABEL-TYPE-SYMBOLOGY
  // so let's skip the LABEL-TYPE- portion to get just the symbology
   sLabelType = sLabelType.substring(11);

  } else {

   // the string was empty so let's set it to "Unknown"
   sLabelType = "Unknown";

  }

   // let's construct the beginning of our output string
   out = sLabelType + ":";

  }

  }

 

   // check if the data has come from the MSR
   if (source.equalsIgnoreCase("msr")) {

   msrReadCount++;

   // construct the beginning of our output string
   out = "(" + msrReadCount + ") ";

  }

 

   // let's get our edit box view
   EditText et = (EditText) findViewById(R.id.output);

  et.setText(out + data);

  }

  }

 

   public void onScannerData(String s) {

   // let's get our edit box view
   EditText et = (EditText) findViewById(R.id.output);

  et.setText(s);

  }

}

 

End MainActivity.java-----------------------------------------

 

Start EMDKConfig.xml-----------------------------------------

<?xml version="1.0" encoding="UTF-8"?><!--This is an auto generated document. Changes to this document may cause incorrect behavior.--><wap-provisioningdoc>

  <characteristic type="ProfileInfo">

  <parm name="created_wizard_version" value="3.1.20"/>

  </characteristic>

  <characteristic type="Profile">

  <parm name="ProfileName" value="QVSProfile"/>

  <parm name="ModifiedDate" value="2015-06-26 14:00:10"/>

  <parm name="TargetSystemVersion" value="4.4"/>

 

  <characteristic type="ActivitySelection" version="0.1">

  <parm name="emdk_name" value="ProfileActivity"/>

  <characteristic type="Application">

  <parm name="package" value="com.example.johnfoley.myapplication"/>

  <characteristic type="Activities">

  <parm name="activity" value="MainActivity"/>

  </characteristic>

  </characteristic>

  </characteristic>

  <characteristic type="MSR" version="0.1">

  <parm name="emdk_name" value="theMsr"/>

  <parm name="msr_input_enabled" value="false"/>

  </characteristic>

  <characteristic type="Barcode" version="3.1">

  <parm name="emdk_name" value="theScanner"/>

  <parm name="scanner_input_enabled" value="false"/>

  <parm name="ScannerSelection" value="AUTO"/>

  <characteristic type="Decoders">

  <parm name="decoder_upca" value="Default"/>

  <parm name="decoder_upce0" value="Default"/>

  <parm name="decoder_ean13" value="Default"/>

  <parm name="decoder_ean8" value="Default"/>

  <parm name="decoder_code128" value="Default"/>

  <parm name="decoder_code39" value="Default"/>

  <parm name="decoder_i2of5" value="Default"/>

  <parm name="decoder_gs1_databar" value="Default"/>

  <parm name="decoder_gs1_databar_lim" value="Default"/>

  <parm name="decoder_gs1_databar_exp" value="Default"/>

  <parm name="decoder_datamatrix" value="Default"/>

  <parm name="decoder_qrcode" value="Default"/>

  <parm name="decoder_pdf417" value="Default"/>

  <parm name="decoder_composite_ab" value="Default"/>

  <parm name="decoder_composite_c" value="Default"/>

  <parm name="decoder_microqr" value="Default"/>

  <parm name="decoder_aztec" value="Default"/>

  <parm name="decoder_maxicode" value="Default"/>

  <parm name="decoder_micropdf" value="Default"/>

  <parm name="decoder_uspostnet" value="Default"/>

  <parm name="decoder_usplanet" value="Default"/>

  <parm name="decoder_uk_postal" value="Default"/>

  <parm name="decoder_japanese_postal" value="Default"/>

  <parm name="decoder_australian_postal" value="Default"/>

  <parm name="decoder_canadian_postal" value="Default"/>

  <parm name="decoder_dutch_postal" value="Default"/>

  <parm name="decoder_us4state" value="Default"/>

  <parm name="decoder_us4state_fics" value="Default"/>

  <parm name="decoder_codabar" value="Default"/>

  <parm name="decoder_msi" value="Default"/>

  <parm name="decoder_code93" value="Default"/>

  <parm name="decoder_trioptic39" value="Default"/>

  <parm name="decoder_d2of5" value="Default"/>

  <parm name="decoder_chinese_2of5" value="Default"/>

  <parm name="decoder_korean_3of5" value="Default"/>

  <parm name="decoder_code11" value="Default"/>

  <parm name="decoder_tlc39" value="Default"/>

  <parm name="decoder_mailmark" value="Default"/>

  <parm name="decoder_hanxin" value="Default"/>

  <parm name="decoder_signature" value="Default"/>

  <parm name="decoder_webcode" value="Default"/>

  <parm name="decoder_matrix_2of5" value="Default"/>

  <parm name="decoder_upce1" value="Default"/>

  </characteristic>

  <characteristic type="DecoderParams">

  <characteristic type="UPCA">

  <parm name="decoder_upca_report_check_digit" value="Default"/>

  <parm name="decoder_upca_preamble" value="Default"/>

  </characteristic>

  <characteristic type="UPCE0">

  <parm name="decoder_upce0_report_check_digit" value="Default"/>

  <parm name="decoder_upce0_preamble" value="Default"/>

  <parm name="decoder_upce0_convert_to_upca" value="Default"/>

  </characteristic>

  <characteristic type="EAN8">

  <parm name="decoder_ean8_convert_to_ean13" value="Default"/>

  </characteristic>

  <characteristic type="Code128">

  <parm name="decoder_code128_length1" value="0"/>

  <parm name="decoder_code128_length2" value="55"/>

  <parm name="decoder_code128_redundancy" value="Default"/>

  <parm name="decoder_code128_enable_plain" value="Default"/>

  <parm name="decoder_code128_enable_ean128" value="Default"/>

  <parm name="decoder_code128_enable_isbt128" value="Default"/>

  <parm name="decoder_code128_isbt128_concat_mode" value="Default"/>

  <parm name="decoder_code128_check_isbt_table" value="Default"/>

  <parm name="decoder_code128_security_level" value="Default"/>

  <parm name="code128_enable_marginless_decode" value="Default"/>

  <parm name="code128_ignore_fnc4" value="Default"/>

  </characteristic>

  <characteristic type="Code39">

  <parm name="decoder_code39_length1" value="0"/>

  <parm name="decoder_code39_length2" value="55"/>

  <parm name="decoder_code39_verify_check_digit" value="Default"/>

  <parm name="decoder_code39_report_check_digit" value="Default"/>

  <parm name="decoder_code39_full_ascii" value="Default"/>

  <parm name="decoder_code39_redundancy" value="Default"/>

  <parm name="decoder_code39_convert_to_code32" value="Default"/>

  <parm name="decoder_code39_report_code32_prefix" value="Default"/>

  <parm name="decoder_code39_security_level" value="Default"/>

  <parm name="code39_enable_marginless_decode" value="Default"/>

  </characteristic>

  <characteristic type="Interleaved_2of5">

  <parm name="decoder_i2of5_length1" value="14"/>

  <parm name="decoder_i2of5_length2" value="10"/>

  <parm name="decoder_i2of5_redundancy" value="Default"/>

  <parm name="decoder_i2of5_check_digit" value="Default"/>

  <parm name="decoder_i2of5_report_check_digit" value="Default"/>

  <parm name="decoder_itf14_convert_to_ean13" value="Default"/>

  <parm name="decoder_i2of5_security_level" value="Default"/>

  <parm name="i20f5_enable_marginless_decode" value="Default"/>

  </characteristic>

  <characteristic type="GS1_Databar_Limited">

  <parm name="decoder_gs1_lim_security_level" value="Default"/>

  </characteristic>

  <characteristic type="Composite_AB">

  <parm name="decoder_composite_ab_ucc_link_mode" value="Default"/>

  </characteristic>

  <characteristic type="US_Postnet">

  <parm name="decoder_uspostnet_report_check_digit" value="Default"/>

  </characteristic>

  <characteristic type="US_Planet">

  <parm name="decoder_usplanet_report_check_digit" value="Default"/>

  </characteristic>

  <characteristic type="UK_Postal">

  <parm name="decoder_uk_postal_report_check_digit" value="Default"/>

  </characteristic>

  <characteristic type="Codabar">

  <parm name="decoder_codabar_length1" value="6"/>

  <parm name="decoder_codabar_length2" value="55"/>

  <parm name="decoder_codabar_redundancy" value="Default"/>

  <parm name="decoder_codabar_clsi_editing" value="Default"/>

  <parm name="decoder_codabar_notis_editing" value="Default"/>

  </characteristic>

  <characteristic type="MSI">

  <parm name="decoder_msi_length1" value="4"/>

  <parm name="decoder_msi_length2" value="55"/>

  <parm name="decoder_msi_redundancy" value="Default"/>

  <parm name="decoder_msi_check_digit" value="Default"/>

  <parm name="decoder_msi_check_digit_scheme" value="Default"/>

  <parm name="decoder_msi_report_check_digit" value="Default"/>

  </characteristic>

  <characteristic type="Code93">

  <parm name="decoder_code93_length1" value="0"/>

  <parm name="decoder_code93_length2" value="55"/>

  <parm name="decoder_code93_redundancy" value="Default"/>

  </characteristic>

  <characteristic type="Trioptic_39">

  <parm name="decoder_trioptic39_redundancy" value="Default"/>

  </characteristic>

  <characteristic type="Discrete_2of5">

  <parm name="decoder_d2of5_length1" value="0"/>

  <parm name="decoder_d2of5_length2" value="14"/>

  <parm name="decoder_d2of5_redundancy" value="Default"/>

  </characteristic>

  <characteristic type="Code11">

  <parm name="decoder_code11_length1" value="4"/>

  <parm name="decoder_code11_length2" value="55"/>

  <parm name="decoder_code11_redundancy" value="Default"/>

  <parm name="decoder_code11_verify_check_digit" value="Default"/>

  <parm name="decoder_code11_report_check_digit" value="Default"/>

  </characteristic>

  <characteristic type="Han_Xin">

  <parm name="decoder_hanxin_inverse" value="Default"/>

  </characteristic>

  <characteristic type="Matrix_2of5">

  <parm name="decoder_matrix_2of5_length1" value="10"/>

  <parm name="decoder_matrix_2of5_length2" value="0"/>

  <parm name="decoder_matrix_2of5_redundancy" value="Default"/>

  <parm name="decoder_matrix_2of5_report_check_digit" value="Default"/>

  <parm name="decoder_matrix_2of5_verify_check_digit" value="Default"/>

  </characteristic>

  <characteristic type="UPCE1">

  <parm name="decoder_upce1_report_check_digit" value="Default"/>

  <parm name="decoder_upce1_preamble" value="Default"/>

  <parm name="decoder_upce1_convert_to_upca" value="Default"/>

  </characteristic>

  </characteristic>

  <characteristic type="UpcEanParams">

  <parm name="upcean_security_level" value="Default"/>

  <parm name="upcean_supplemental2" value="Default"/>

  <parm name="upcean_supplemental5" value="Default"/>

  <parm name="upcean_supplemental_mode" value="Default"/>

  <parm name="upcean_retry_count" value="10"/>

  <parm name="upcean_random_weight_check_digit" value="Default"/>

  <parm name="upcean_linear_decode" value="Default"/>

  <parm name="upcean_bookland" value="Default"/>

  <parm name="upcean_coupon" value="Default"/>

  <parm name="upcean_coupon_report" value="Default"/>

  <parm name="upcean_ean_zero_extend" value="Default"/>

  <parm name="upcean_bookland_format" value="Default"/>

  <parm name="databar_to_upc_ean" value="Default"/>

  <parm name="upc_enable_marginless_decode" value="Default"/>

  </characteristic>

  <characteristic type="ReaderParams">

  <parm name="beam_timer" value="5000"/>

  <parm name="Adaptive_Scanning" value="Default"/>

  <parm name="Beam_Width" value="Default"/>

  <parm name="power_mode" value="Default"/>

  <parm name="mpd_mode" value="Default"/>

  <parm name="reader_mode" value="Default"/>

  <parm name="linear_security_level" value="Default"/>

  <parm name="picklist" value="Default"/>

  <parm name="aim_type" value="Default"/>

  <parm name="same_barcode_timeout" value="500"/>

  <parm name="different_barcode_timeout" value="500"/>

  <parm name="illumination_mode" value="Default"/>

  <parm name="lcd_mode" value="Default"/>

  <parm name="delay_to_low_power_mode" value="Default"/>

  <parm name="illumination_brightness" value="10"/>

  <parm name="inverse_1d_mode" value="Default"/>

  <parm name="1d_marginless_decode_effort_level" value="Default"/>

  <parm name="poor_quality_bcdecode_effort_level" value="Default"/>

  <parm name="viewfinder_mode" value="Default"/>

  </characteristic>

  <characteristic type="ScanParams">

  <parm name="code_id_type" value="Default"/>

  <parm name="volume_slider_type" value="Default"/>

  <parm name="decode_audio_feedback_uri" value=""/>

  <parm name="decode_haptic_feedback" value="Default"/>

  <parm name="bt_disconnect_on_exit" value="Default"/>

  <parm name="connection_idle_time" value="600"/>

  <parm name="establish_connection_time" value="45"/>

  <parm name="display_bt_address_barcode" value="Default"/>

  <parm name="good_decode_led_timer" value="75"/>

  <parm name="decoding_led_feedback" value="Default"/>

  </characteristic>

  </characteristic>

  <characteristic type="Intent" version="0.1">

  <parm name="emdk_name" value="dataCaptureIntent"/>

  <parm name="intent_output_enabled" value="true"/>

  <parm name="intent_action" value="com.example.johnfoley.myapplication.RECVR"/>

  <parm name="intent_category" value="android.intent.category.DEFAULT"/>

  <parm name="intent_delivery" value="0"/>

  <characteristic type="BasicDataFormatting">

  <parm name="bdf_enabled" value="true"/>

  <parm name="bdf_prefix" value=""/>

  <parm name="bdf_suffix" value=""/>

  <parm name="bdf_send_data" value="true"/>

  <parm name="bdf_send_hex" value="Default"/>

  <parm name="bdf_send_tab" value="Default"/>

  <parm name="bdf_send_enter" value="Default"/>

  </characteristic>

  </characteristic>

  <characteristic type="Keystroke" version="0.1">

  <parm name="emdk_name" value=""/>

  <parm name="ime_output_enabled" value="false"/>

  <parm name="keystroke_action_char" value="Default"/>

  <characteristic type="BasicDataFormatting">

  <parm name="bdf_enabled" value="Default"/>

  <parm name="bdf_prefix" value=""/>

  <parm name="bdf_suffix" value=""/>

  <parm name="bdf_send_data" value="Default"/>

  <parm name="bdf_send_hex" value="Default"/>

  <parm name="bdf_send_tab" value="Default"/>

  <parm name="bdf_send_enter" value="Default"/>

  </characteristic>

  </characteristic>

  </characteristic>

</wap-provisioningdoc>

 

End EMDKConfig.xml-----------------------------------------