获取配置

DataWedge 7.4

GET_CONFIG

获取指定配置文件中的 PARAM_LIST 设置,作为一套值对或插件配置捆绑包返回。

版本历史记录

  • 在 DataWedge 6.5 中引入
  • DataWedge 6.8 - 增加了对 ADF 设置的支持
  • DataWedge 6.9/7.0 - 增加了对 Voice Input 和全局扫描器配置的支持。
  • DataWedge 7.1 - 增加了对以下配置的支持:完整配置文件、Data Capture Plus (DCP)、磁条读取器 (MSR)、Internet 协议 (IP)、Simulscan
  • DataWedge 7.3.22 - 增加了对新 RFID 输入功能的支持。

函数原型

Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", "<profile name>");

参数

ACTION [字符串]:"com.symbol.datawedge.api.ACTION"

EXTRA_DATA [字符串]:"com.symbol.datawedge.api.GET_CONFIG"

EXTRA VALUE [捆绑包]:"<PROFILE_NAME>", "<PLUGIN_CONFIG>"

  • PLUGIN_CONFIG [捆绑包] -
    • PLUGIN_NAME [字符串] - 单个插件名称(例如“条码”)或插件名称的 ArrayList:
    • PROCESS_PLUGIN_NAME [捆绑包列表] - 例如:
      • PLUGIN_NAME - "ADF", "BDF"
      • OUTPUT_PLUGIN_NAME - "KEYSTROKE"
    • ...
      • PLUGIN_NAME - "BDF"
      • OUTPUT_PLUGIN_NAME - "INTENT"

注意:

  • PROCESS_PLUGIN_NAME 参数必须用于查询处理插件(ADF 和 BDF);默认 GET_CONFIG Intent 无法检索有关处理插件的信息。
  • 不存在的值会作为空的额外项返回。

SCANNER_IDENTIFIER:存在于设备中支持的每个扫描器的每个扫描器信息捆绑包中。DataWedge 6.6 及更高版本支持 Index 和 identifier 参数;如果在代码中也引用了索引,则扫描器标识符值优先。

  • scanner_selection_by_identifier [字符串] - 从扫描器标识符的列表取值如下:
    • AUTO - 自动扫描器选择
    • INTERNAL_IMAGER - 内置成像器扫描器
    • INTERNAL_LASER - 内置激光扫描器
    • INTERNAL_CAMERA - 内置摄像头扫描器
    • SERIAL_SSI - 用于 ET50/ET55 的可插入 Z 式背面扫描器
    • BLUETOOTH_SSI - RS507 蓝牙扫描器
    • BLUETOOTH_RS6000 - RS6000 蓝牙扫描器
    • BLUETOOTH_DS3678 - DS3678 蓝牙扫描器
    • PLUGABLE_SSI - 串行 SSI 扫描器 RS429(与 WT6000 一起使用)
    • PLUGABLE_SSI_RS5000 - 串行 SSI 扫描器 RS5000(与 WT6000 一起使用)
    • USB_SSI_DS3608 - DS3608 可插入 USB 扫描器

返回值

返回带配置文件名称、状态和包含 PARAM_LIST 捆绑包的配置文件的嵌套捆绑包。

EXTRA NAME:"com.symbol.datawedge.api.GET_CONFIG_RESULT"

BUNDLE:<主捆绑包>(请参阅下面的参数)

主捆绑包

主捆绑包 Get_Result_Config 包含以下属性:

PROFILE_NAME [字符串]:要查询的配置文件的名称

PROFILE_ENABLED [字符串]:True/False

PLUGIN_CONFIG [捆绑包]:具有以下属性的嵌套捆绑包:

  • PLUGIN_NAME [字符串]:要报告的插件的名称(例如条码)
  • PARAM_LIST [捆绑包]:名称-值对的嵌套列表。例如:
    • current-device-index, 0
    • Aztec, True
    • Canadian_Postal, False
    • Code11, Null(重置为默认值)
    • Picklist, HARDWARE
    • AimType, PRESS_AND_RELEASE
    • ...(等等)

将错误和调试消息记录到可通过 logcat 命令查看和过滤的 Android 日志记录系统。从 ADB Shell 使用 logcat 查看日志消息:

$ adb logcat -s DWAPI

记录无效操作和参数的错误消息。

示例代码

发送 GET_CONFIG Intent

Bundle bMain = new Bundle(); bMain.putString("PROFILE_NAME", "DWDemo"); Bundle bConfig = new Bundle(); ArrayList<Bundle> pluginName = new ArrayList<>(); Bundle pluginInternal = new Bundle(); pluginInternal.putString("PLUGIN_NAME", "ADF");//can put a list "ADF,BDF" pluginInternal.putString("OUTPUT_PLUGIN_NAME","KEYSTROKE"); pluginName.add(pluginInternal); bConfig.putParcelableArrayList("PROCESS_PLUGIN_NAME", pluginName); bMain.putBundle("PLUGIN_CONFIG", bConfig); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain); this.sendBroadcast(i);

接收 GET_CONFIG 结果

private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Bundle extras = intent.getExtras(); Set<String> keys = extras.keySet(); for(String key: keys){ Log.d(TAG,"key:"+key); } if (extras.containsKey("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle bundle = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); if(bundle != null && !bundle.isEmpty()){ String profileName = bundle.getString("PROFILE_NAME"); String profileEnabled = bundle.getString("PROFILE_ENABLED"); ArrayList<Bundle> configBundleList = bundle.getParcelableArrayList("PLUGIN_CONFIG"); if(configBundleList!=null) { for (Bundle configBundle : configBundleList) { String pluginName = configBundle.getString("PLUGIN_NAME"); Log.d(TAG, "\n Plugin Name :" + pluginName); if (pluginName!=null && pluginName.equalsIgnoreCase("ADF")) { String pluginEnabled = configBundle.getString("adf_enabled"); Log.d(TAG, " Plugin Enabled :" + pluginEnabled); if(configBundle.containsKey("PARAM_LIST")){ Object object = configBundle.get("PARAM_LIST"); if(object!=null && object instanceof ArrayList){ ArrayList<Bundle> paramArrayList = (ArrayList)object; for(Bundle rule : paramArrayList){ String name = rule.getString("name"); String enabled = rule.getString("enabled"); String priority = rule.getString("priority"); String alldevices = rule.getString("alldevices"); String string = rule.getString("string"); String stringPos = rule.getString("string_pos"); String stringLen = rule.getString("string_len"); Log.d(TAG, "Rule ->"); Log.d(TAG, " name :" + name); Log.d(TAG, " enabled :" + enabled); Log.d(TAG, " priority :" + priority); Log.d(TAG, " alldevices :" + alldevices); Log.d(TAG, " string :" + string); Log.d(TAG, " stringPos :" + stringPos); Log.d(TAG, " stringLen :" + stringLen); ArrayList<Bundle> actions = rule.getParcelableArrayList("ACTIONS"); if(actions!=null){ Log.d(TAG,"\n Actions->"); for(Bundle action: actions){ String type = action.getString("type"); Object param_1 = action.get("action_param_1"); Object param_2 = action.get("action_param_2"); Object param_3 = action.get("action_param_3"); Log.d(TAG," type:"+type); if(param_1!=null && param_1 instanceof String){ Log.d(TAG," param_1:"+param_1); } if(param_2!=null && param_2 instanceof String){ Log.d(TAG," param_2:"+param_2); } if(param_3!=null && param_3 instanceof String){ Log.d(TAG," param_3:"+param_3); } } } ArrayList<Bundle> devices = rule.getParcelableArrayList("DEVICES"); if(devices!=null){ Log.d(TAG,"\n Devices->"); for(Bundle device: devices){ String type = device.getString("device_id"); Object param_1 = device.get("enabled"); Object param_2 = device.get("alldecoders"); Object param_3 = device.get("all_label_ids"); Log.d(TAG," Device ID:"+type); if(param_1!=null && param_1 instanceof String){ Log.d(TAG," Enabled:"+param_1); } if(param_2!=null && param_2 instanceof String){ Log.d(TAG," All decoders:"+param_2); } if(param_3!=null && param_3 instanceof String){ Log.d(TAG," All labelids:"+param_3); } } } ArrayList<Bundle> decoders = rule.getParcelableArrayList("DECODERS"); if(decoders!=null){ Log.d(TAG,"\n Decoders->"); for(Bundle decoder: decoders){ String deviceID = decoder.getString("device_id"); String decoderEnabled = decoder.getString("enabled"); String decoderID = decoder.getString("decoder"); Log.d(TAG," Device ID:"+deviceID); Log.d(TAG," Decoder Enabled:"+decoderEnabled); Log.d(TAG," Decoder ID:"+decoderID); } } ArrayList<Bundle> labelIDs = rule.getParcelableArrayList("LABEL_IDS"); if(labelIDs!=null){ Log.d(TAG,"\n LabelIDs->"); for(Bundle labelID: labelIDs){ String deviceID = labelID.getString("device_id"); String lblEnabled = labelID.getString("enabled"); String lblID = labelID.getString("label_id"); Log.d(TAG," Device ID:"+deviceID); Log.d(TAG," Label Enabled:"+lblEnabled); Log.d(TAG," Label ID:"+lblID); } } } } } } }

获取插件

// SENDING THE INTENT Bundle bMain = new Bundle(); bMain.putString("PROFILE_NAME", "Profile0 (default)"); Bundle bConfig = new Bundle(); ArrayList<String> pluginName = new ArrayList<>(); pluginName.add("BARCODE"); // pluginName.add("INTENT"); to add more plugins bConfig.putStringArrayList("PLUGIN_NAME", pluginName); bMain.putBundle("PLUGIN_CONFIG", bConfig); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain); this.sendBroadcast(i); // RECEIVING THE RESULT private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle result = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); Set<String> keys = result.keySet(); for (String key : keys) { if (!key.equalsIgnoreCase("PLUGIN_CONFIG")) { Log.d("DWScannerConfig", "DWGetConfig::level-1: " + key + " : " + result.getString(key)); } else { ArrayList<Bundle> bundleArrayList = result.getParcelableArrayList("PLUGIN_CONFIG"); for(Bundle configBundle:bundleArrayList){ Set<String> keys2 = configBundle.keySet(); for (String key2 : keys2) { if (!key2.equalsIgnoreCase("PARAM_LIST")) { } else { Bundle params = configBundle.getBundle("PARAM_LIST"); Set<String> keys3 = params.keySet(); for (String key3 : keys3) { //TODO consume the params } } } } } } } } };

获取应用程序关联

// SENDING THE INTENT selectedProfileName = "DWDemo"; Bundle bConfig = new Bundle(); bConfig.putString("PROFILE_NAME", selectedProfileName); bConfig.putString("APP_LIST", "");//empty Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bConfig); this.sendBroadcast(i); // RECEIVING THE RESULT private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.d(TAG, "Action: " + action); if(action.equals("com.symbol.datawedge.api.RESULT_ACTION")){ Bundle b = intent.getExtras(); // getConfig result if(intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle res = b.getBundle("com.symbol.datawedge.api.RESULT_GET_CONFIG"); if(!res.isEmpty()) { String profileName = res.getString("PROFILE_NAME"); Log.d(TAG, "GET_CONFIG profileName: " + profileName); ArrayList<Bundle> appList = res.getParcelableArrayList("APP_LIST"); if(appList == null){ Log.d(TAG,"Profile information is not found for "+profileName); }else if(appList.size() == 0){ Log.d(TAG,"Profile "+profileName+" has no associated information"); }else { for(Bundle b1 :appList ){ Log.d(TAG,b1.getString("PACKAGE_NAME")+":"+b1.getStringArrayList("ACTIVITY_LIST")); } } } } } } };

获取扫描器状态

// SENDING THE INTENT Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_SCANNER_STATUS","STANDARD"); i.putExtra("SEND_RESULT","LAST_RESULT"); // i.putExtra("SEND_RESULT", "true"); // For versions prior to DataWedge 7.1 i.putExtra("com.symbol.datawedge.api.RESULT_CATEGORY","android.intent.category.DEFAULT"); this.sendBroadcast(i); // RECEIVING THE RESULT private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver(){ @Override public void onReceive(Context context, Intent intent){ if (intent != null) { String command = intent.getStringExtra("COMMAND"); String commandidentifier = intent.getStringExtra("COMMAND_IDENTIFIER"); String result = intent.getStringExtra("RESULT"); Bundle bundle = new Bundle(); String resultInfo = ""; if (intent.hasExtra("RESULT_INFO")) { bundle = intent.getBundleExtra("RESULT_INFO"); Set<String> keys = bundle.keySet(); for (String key : keys) { resultInfo += key + ": " + bundle.getString(key) + "\n"; } } String text = "Command: " + command + "\n" + "Result: " + result + "\n" + "Result Info: \n" + resultInfo + "\n" + "CID:" + commandidentifier; Log.d("TAG", "#DataWedgeTestApp# \nCommand: " + command + "\nResult: " + result + "\nReason:\n" + resultInfo); Toast.makeText(context, text, Toast.LENGTH_LONG).show(); } }; };

获取扫描器详细信息

//Bundle extras = intent.getExtras(); if (intent.hasExtra(RESULT_ACTION_EXTRA_GET_CONFIG)) { Bundle results = intent.getBundleExtra(RESULT_ACTION_EXTRA_GET_CONFIG); if(results!=null){ if(results.containsKey(BUNDLE_EXTRA_PLUGIN_CONFIG)){ ArrayList<Bundle> list = (ArrayList<Bundle>)results.get(BUNDLE_EXTRA_PLUGIN_CONFIG); Bundle x = new Bundle(); if(list!=null){ for(Bundle it : list){ if(it.containsKey(BUNDLE_EXTRA_PARAM_LIST)){ Bundle b =(Bundle)it.get(BUNDLE_EXTRA_PARAM_LIST); String sEnabled = b.getString("scanner_input_enabled"); String sSelection = b.getString("scanner_selection"); String sSelectionId = b.getString("scanner_selection_by_identifier"); String sType = b.getString("scanner_type"); Log.d(TAG,"scanner_selection : "+sSelection); Log.d(TAG,"scanner_selection_by_identifier : "+sSelectionId); } } } } } }

获取字符间设置

private Integer ctrlCharacterDelayValue; private Integer genericCharacterDelayValue; private Boolean flagExtendedASCIIOnly; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); registerReceivers(); ctrlCharacterDelayValue = null; genericCharacterDelayValue = null; flagExtendedASCIIOnly = null; } private void registerReceivers() { IntentFilter filter = new IntentFilter(); filter.addAction("com.symbol.datawedge.api.RESULT_ACTION"); filter.addCategory(Intent.CATEGORY_DEFAULT); registerReceiver(broadcastReceiver, filter); } @Override protected void onDestroy() { super.onDestroy(); unregisterReceiver(broadcastReceiver); } //Get configuration public void getKeyStrokeConfiguration(View arg){ Bundle bMain = new Bundle(); bMain.putString("PROFILE_NAME","Profile0 (default)"); Bundle bConfig = new Bundle(); bConfig.putString("PLUGIN_NAME","KEYSTROKE"); bMain.putBundle("PLUGIN_CONFIG", bConfig); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain); this.sendBroadcast(i); } //broadcast receiver private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.d(TAG, "#DataWedge-APP# Action: " + action); //result of get config if(intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")){ Bundle bundle = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); if(bundle != null && !bundle.isEmpty()){ String profileName = bundle.getString("PROFILE_NAME"); String profileEnabled = bundle.getString("PROFILE_ENABLED"); ArrayList<Bundle> configBundleList = bundle.getParcelableArrayList("PLUGIN_CONFIG"); if(configBundleList!=null) { for (Bundle configBundle : configBundleList) { if (configBundle.getString("PLUGIN_NAME").equalsIgnoreCase("KEYSTROKE")) { Bundle paramBundle = configBundle.getBundle("PARAM_LIST"); String keyStrokePluginEnabled = paramBundle.getString("keystroke_output_enabled"); String mExtendedAsciiDelay = paramBundle.getString("keystroke_delay_extended_ascii"); String mCtrlDelay = paramBundle.getString("keystroke_delay_control_chars"); String actionKeyChar = paramBundle.getString("keystroke_action_char"); Log.d(TAG, " ProfileName :" + profileName); Log.d(TAG, " Profile enabled :" + profileEnabled); Log.d(TAG, " Plugin enabled :" + keyStrokePluginEnabled); Log.d(TAG, " Ctrl Char Delay :" + mCtrlDelay); Log.d(TAG, " Character Delay :" + mExtendedAsciiDelay); Log.d(TAG, " ActionKey Char :" + actionKeyChar); } } } } }//end get config }//end onRecieve };

获取令牌处理

public void getConfig() { Bundle bMain = new Bundle(); bMain.putString("PROFILE_NAME", "Profile007"); Bundle bConfig = new Bundle(); Bundle processPlugin_TOKEN_IP = new Bundle(); processPlugin_TOKEN_IP.putString("PLUGIN_NAME", "TOKEN"); processPlugin_TOKEN_IP.putString("OUTPUT_PLUGIN_NAME", "KEYSTROKE"); // Tokens are supported only in KEYSTROKE and IP plugins only, for others empty bundle will be returned. bConfig.putBundle("PROCESS_PLUGIN_NAME", processPlugin_TOKEN_IP); bMain.putBundle("PLUGIN_CONFIG", bConfig); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain); this.sendBroadcast(i); } private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); String strFinalResult = ""; String command = intent.getStringExtra("COMMAND"); String commandidentifier = intent.getStringExtra("COMMAND_IDENTIFIER"); String result = intent.getStringExtra("RESULT"); Bundle bundle = new Bundle(); String resultInfo = ""; if (action.equals("com.symbol.datawedge.api.RESULT_ACTION")) { if (intent.hasExtra("RESULT_INFO")) { bundle = intent.getBundleExtra("RESULT_INFO"); Set<String> keys = bundle.keySet(); for (String key : keys) { String val = bundle.getString(key); if (val == null) { if (bundle.getStringArray(key) != null) { val = ""; for (String s : bundle.getStringArray(key)) { val += "" + s + "\n"; } } } resultInfo += key + ": " + val + "\n"; } } else if (intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle resultGetConfig = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); Set<String> keys = resultGetConfig.keySet(); for (String key : keys) { if (key.equalsIgnoreCase("PLUGIN_CONFIG")) { ArrayList<Bundle> bundleArrayList = resultGetConfig.getParcelableArrayList("PLUGIN_CONFIG"); for (Bundle configBundle : bundleArrayList) { String pluginName = configBundle.getString("PLUGIN_NAME"); strFinalResult += "\nPlugin " + pluginName + " Settings\n"; if (pluginName != null && pluginName.equalsIgnoreCase("TOKEN")) { strFinalResult += "\nPlugin " + configBundle.getString("OUTPUT_PLUGIN_NAME") + " TOKEN Settings\n"; Set<String> keys2 = configBundle.keySet(); for (String key2 : keys2) { if (!key2.equalsIgnoreCase("PARAM_LIST")) { } else { Bundle params = configBundle.getBundle("PARAM_LIST"); Set<String> keys3 = params.keySet(); for (String key3 : keys3) { if (key3.equalsIgnoreCase("token_order")) { strFinalResult += "\n" + key3 + ": token_order\n"; ArrayList<Bundle> tokenOrderList = params.getParcelableArrayList("token_order"); int order = 0; for (Bundle b : tokenOrderList) { strFinalResult += "\t" + order + ". " + b.getString("name") + ": " + b.getString("enabled") + "\n"; order++; } } else { strFinalResult += "\n" + key3 + ": " + params.get(key3); } } } } strFinalResult += "\n"; } } } } Log.d("TAG", "#IntentApp#\n\nGet config info received\n" + strFinalResult); } if (command != null) { if (command.equalsIgnoreCase("com.symbol.datawedge.api.SET_CONFIG")) { Log.d("TAG", "#IntentApp# \n\nSetConfig status received: " + result + "\nResultInfo: " + resultInfo); } } } } };

获取 RFID 输入配置

private void getIntentConfigRFID() {         Bundle bMain = new Bundle();         bMain.putString("PROFILE_NAME", "SampleConfigApi");         Bundle bConfig = new Bundle();         ArrayList<String> pluginName = new ArrayList<>();         pluginName.add("RFID");          bConfig.putStringArrayList("PLUGIN_NAME", pluginName);         bMain.putBundle("PLUGIN_CONFIG", bConfig);          Intent i = new Intent();         i.setAction("com.symbol.datawedge.api.ACTION");         i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain);         this.sendBroadcast(i);     }   // BroadcastReceiver to handle incoming data      private BroadcastReceiver reciveResulyBroadcast = new BroadcastReceiver(){          @Override         public void onReceive(Context context, Intent intent) {             if (intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) {                 Bundle result = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG");                 Set<String> keys = result.keySet();                 for (String key : keys) { ;                     if (!key.equalsIgnoreCase("PLUGIN_CONFIG")) {                         Log.d("DWScannerConfig", "DWGetConfig::level-1: " + key + " : " + result.getString(key));                     } else {                         ArrayList<Bundle> bundleArrayList = result.getParcelableArrayList("PLUGIN_CONFIG");                         for (Bundle configBundle : bundleArrayList) {                             Set<String> keys2 = configBundle.keySet();                             for (String key2 : keys2) {                                 if (!key2.equalsIgnoreCase("PARAM_LIST")) {                                 } else {                                     Bundle params = configBundle.getBundle("PARAM_LIST");                                     Set<String> keys3 = params.keySet();                                      String configs =intentData.getText()+"\n\n\n" +configBundle.getString("PLUGIN_NAME")+"\n";                                     for (String key3 : keys3) {                                         configs+= key3+"="+params.getString(key3)+"\n";                                     }                                      intentData.setText(configs);                                 }                             }                         }                     }                 }             }         }  }

设置串行输入配置

final String RESULT_ACTION = "com.symbol.datawedge.api.RESULT_ACTION"; final static String DEFAULT_CATEGORY = "android.intent.category.DEFAULT"; TextView status; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); IntentFilter filter = new IntentFilter(); filter.addAction(RESULT_ACTION); filter.addCategory(DEFAULT_CATEGORY); registerReceiver(dwResultReciever, filter); } public void btnGetOnClick(View view) { status.setText(""); //MAIN BUNDLE PROPERTIES Bundle bMain = new Bundle(); bMain.putString("PROFILE_NAME", "Profile0 (default)"); //bMain.putString("PROFILE_NAME", "DWDemo"); //PLUGIN_CONFIG BUNDLE PROPERTIES Bundle bConfig = new Bundle(); ArrayList<String> pluginName = new ArrayList<>(); pluginName.add("SERIAL"); bConfig.putStringArrayList("PLUGIN_NAME", pluginName); bMain.putBundle("PLUGIN_CONFIG", bConfig); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("SEND_RESULT","LAST_RESULT"); // i.putExtra("SEND_RESULT", "true"); // For versions prior to DataWedge 7.1 i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain); this.sendBroadcast(i); } private BroadcastReceiver dwResultReciever = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String text = ""; if (intent.getAction().equalsIgnoreCase("com.symbol.datawedge.api.RESULT_ACTION")) { if (intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle bundle = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); if (bundle != null && !bundle.isEmpty()) { String profileName = bundle.getString("PROFILE_NAME"); String profileEnabled = bundle.getString("PROFILE_ENABLED"); ArrayList<Bundle> configBundleList = bundle.getParcelableArrayList("PLUGIN_CONFIG"); if (configBundleList != null) { for (Bundle configBundle : configBundleList) { if (configBundle.getString("PLUGIN_NAME").equalsIgnoreCase("SERIAL")) { Parcelable[] deviceBundleList = configBundle.getParcelableArray("DEVICE_LIST"); for (Parcelable parcelableDevice : deviceBundleList) { Bundle device = (Bundle) parcelableDevice; Log.d("TAG", "#Serial# " + device.getString("serial_port_id")); Log.d("TAG", "#Serial# " + device.getString("serial_input_enabled")); Log.d("TAG", "#Serial# " + device.getString("serial_baudrate")); Log.d("TAG", "#Serial# " + device.getString("serial_databits")); Log.d("TAG", "#Serial# " + device.getString("serial_parity")); Log.d("TAG", "#Serial# " + device.getString("serial_stopbits")); Log.d("TAG", "#Serial# " + device.getString("serial_flow")); } } } } } } status.setText("Status:\n" + text); } } };

设置 SIMULSCAN 输入配置

public void getConfig() { Bundle bMain = new Bundle(); bMain.putString("PROFILE_NAME", "Profile007"); Bundle bConfig = new Bundle(); ArrayList<String> pluginName = new ArrayList<>(); pluginName.add("SIMULSCAN"); bConfig.putStringArrayList("PLUGIN_NAME", pluginName); bMain.putBundle("PLUGIN_CONFIG", bConfig); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain); this.sendBroadcast(i); } private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); String strFinalResult = ""; String command = intent.getStringExtra("COMMAND"); String commandidentifier = intent.getStringExtra("COMMAND_IDENTIFIER"); String result = intent.getStringExtra("RESULT"); Bundle bundle = new Bundle(); String resultInfo = ""; if (action.equals("com.symbol.datawedge.api.RESULT_ACTION")) { if (intent.hasExtra("RESULT_INFO")) { bundle = intent.getBundleExtra("RESULT_INFO"); Set<String> keys = bundle.keySet(); for (String key : keys) { String val = bundle.getString(key); if(val == null) { if(bundle.getStringArray(key) != null) { val=""; for (String s : bundle.getStringArray(key)) { val += "" + s + "\n"; } } } resultInfo += key + ": " + val + "\n"; } } else if (intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle resultGetConfig = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); Set<String> keys = resultGetConfig.keySet(); String profileName = resultGetConfig.getString("PROFILE_NAME"); for (String key : keys) { if (key.equalsIgnoreCase("PLUGIN_CONFIG")) { ArrayList<Bundle> bundleArrayList = resultGetConfig.getParcelableArrayList("PLUGIN_CONFIG"); for (Bundle configBundle : bundleArrayList) { strFinalResult += "\nPlugin " + configBundle.getString("PLUGIN_NAME") + " Settings\n"; for (String configBundleKey : configBundle.keySet()) { if (configBundleKey.equalsIgnoreCase("PARAM_LIST")) { Bundle params = configBundle.getBundle("PARAM_LIST"); for (String paramKey : params.keySet()) { if(paramKey.equalsIgnoreCase("simulscan_template_params")) { Bundle simulscan_template_params = params.getBundle("simulscan_template_params"); if (simulscan_template_params != null) { strFinalResult += "\n\tDynamic template params"; for (String template_param : simulscan_template_params.keySet()) { strFinalResult += "\n\t\t" + template_param + ": " + simulscan_template_params.get(template_param); } } } else { strFinalResult += "\n\t" + paramKey + ": " + params.get(paramKey); } } } } strFinalResult += "\n"; } } } Log.d("TAG","#IntentApp#\n\nGet config info received\n" + strFinalResult); } if (command != null) { if (command.equalsIgnoreCase("com.symbol.datawedge.api.SET_CONFIG")) { Log.d("TAG","#IntentApp# \n\nSetConfig status received: " + result + "\nResultInfo: " + resultInfo); } } } } };

设置 DCP 输入配置

// Get Data Capture Plus Input configuration public void getConfig() { Bundle bMain = new Bundle(); bMain.putString("PROFILE_NAME", "Profile007"); bMain.putString("DCP", ""); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain); this.sendBroadcast(i); } private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); String strFinalResult = ""; String command = intent.getStringExtra("COMMAND"); String commandidentifier = intent.getStringExtra("COMMAND_IDENTIFIER"); String result = intent.getStringExtra("RESULT"); Bundle bundle = new Bundle(); String resultInfo = ""; if (action.equals("com.symbol.datawedge.api.RESULT_ACTION")) { if (intent.hasExtra("RESULT_INFO")) { bundle = intent.getBundleExtra("RESULT_INFO"); Set<String> keys = bundle.keySet(); for (String key : keys) { String val = bundle.getString(key); if (val == null) { if (bundle.getStringArray(key) != null) { val = ""; for (String s : bundle.getStringArray(key)) { val += "" + s + "\n"; } } } resultInfo += key + ": " + val + "\n"; } } else if (intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle resultGetConfig = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); Set<String> keys = resultGetConfig.keySet(); String profileName = resultGetConfig.getString("PROFILE_NAME"); for (String key : keys) { if (key.equalsIgnoreCase("DCP")) { strFinalResult += "\n"; Bundle dcpSettings = resultGetConfig.getBundle("DCP"); if (dcpSettings == null) { strFinalResult += "\nDCP Settings are not found for " + profileName; } else { strFinalResult += "\nDCP Settings"; for (String dcpKey : dcpSettings.keySet()) { strFinalResult += "\n\t\t" + dcpKey + ": " + dcpSettings.getString(dcpKey); } } strFinalResult += "\n"; } } Log.d("TAG", "#IntentApp#\n\nGet config info received\n" + strFinalResult); } if (command != null) { if (command.equalsIgnoreCase("com.symbol.datawedge.api.SET_CONFIG")) { Log.d("TAG", "#IntentApp# \n\nSetConfig status received: " + result + "\nResultInfo: " + resultInfo); } } } } };

设置 MSR 输入配置

// Get Magnetic Stripe Reader Input configuration public void getConfig() { Bundle bMain = new Bundle(); bMain.putString("PROFILE_NAME", "Profile007"); Bundle bConfig = new Bundle(); bConfig.putString("PLUGIN_NAME", "MSR"); bMain.putBundle("PLUGIN_CONFIG", bConfig); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain); this.sendBroadcast(i); } private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); String strFinalResult = ""; String command = intent.getStringExtra("COMMAND"); String commandidentifier = intent.getStringExtra("COMMAND_IDENTIFIER"); String result = intent.getStringExtra("RESULT"); Bundle bundle = new Bundle(); String resultInfo = ""; if (action.equals("com.symbol.datawedge.api.RESULT_ACTION")) { if (intent.hasExtra("RESULT_INFO")) { bundle = intent.getBundleExtra("RESULT_INFO"); Set<String> keys = bundle.keySet(); for (String key : keys) { String val = bundle.getString(key); if(val == null) { if(bundle.getStringArray(key) != null) { val=""; for (String s : bundle.getStringArray(key)) { val += "" + s + "\n"; } } } resultInfo += key + ": " + val + "\n"; } } else if (intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle resultGetConfig = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); Set<String> keys = resultGetConfig.keySet(); String profileName = resultGetConfig.getString("PROFILE_NAME"); for (String key : keys) { if (key.equalsIgnoreCase("PLUGIN_CONFIG")) { ArrayList<Bundle> bundleArrayList = resultGetConfig.getParcelableArrayList("PLUGIN_CONFIG"); for (Bundle configBundle : bundleArrayList) { strFinalResult += "\nPlugin " + configBundle.getString("PLUGIN_NAME") + " Settings\n"; for (String configBundleKey : configBundle.keySet()) { if (configBundleKey.equalsIgnoreCase("PARAM_LIST")) { Bundle params = configBundle.getBundle("PARAM_LIST"); for (String paramKey : params.keySet()) { strFinalResult += "\n\t" + paramKey + ": " + params.get(paramKey); } } } strFinalResult += "\n"; } } } Log.d("TAG","#IntentApp#\n\nGet config info received\n" + strFinalResult); } if (command != null) { if (command.equalsIgnoreCase("com.symbol.datawedge.api.SET_CONFIG")) { Log.d("TAG","#IntentApp# \n\nSetConfig status received: " + result + "\nResultInfo: " + resultInfo); } } } } };

使用单个 Intent 获取多个模块的配置(完整配置文件)

从 DataWedge 7.1 开始支持。以前的 DataWedge 版本需要多个 Intent 调用,以从多个模块(插件、APP_LIST 和 Data Capture Plus)中检索信息。

// Get full profile configuration in a single broadcast intent and process the result @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); IntentFilter filter = new IntentFilter(); filter.addAction("com.symbol.datawedge.api.RESULT_ACTION"); filter.addCategory("android.intent.category.DEFAULT"); registerReceiver(broadcastReceiver, filter); getConfig(); } public void getConfig() { Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", "Profile007"); this.sendBroadcast(i); } private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); String strFinalResult = ""; if (action.equals("com.symbol.datawedge.api.RESULT_ACTION")) { if (intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle resultGetConfig = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); Set<String> keys = resultGetConfig.keySet(); String profileName = resultGetConfig.getString("PROFILE_NAME"); for (String key : keys) { if (key.equalsIgnoreCase("PLUGIN_CONFIG")) { ArrayList<Bundle> bundleArrayList = resultGetConfig.getParcelableArrayList("PLUGIN_CONFIG"); for (Bundle configBundle : bundleArrayList) { String pluginName = configBundle.getString("PLUGIN_NAME"); if (pluginName != null && pluginName.equalsIgnoreCase("ADF")) { strFinalResult += "\nPlugin " + configBundle.getString("OUTPUT_PLUGIN_NAME") + " ADF Settings\n"; String pluginEnabled = configBundle.getString("adf_enabled"); strFinalResult += "\n Plugin Enabled :" + pluginEnabled; if (configBundle.containsKey("PARAM_LIST")) { Object object = configBundle.get("PARAM_LIST"); if (object != null && object instanceof ArrayList) { ArrayList<Bundle> paramArrayList = (ArrayList) object; for (Bundle rule : paramArrayList) { String name = rule.getString("name"); String enabled = rule.getString("enabled"); String priority = rule.getString("priority"); String alldevices = rule.getString("alldevices"); String string = rule.getString("string"); String stringPos = rule.getString("string_pos"); String stringLen = rule.getString("string_len"); strFinalResult += "\nRule ->"; strFinalResult += "\n name :" + name; strFinalResult += "\n enabled :" + enabled; strFinalResult += "\n priority :" + priority; strFinalResult += "\n alldevices :" + alldevices; strFinalResult += "\n string :" + string; strFinalResult += "\n stringPos :" + stringPos; strFinalResult += "\n stringLen :" + stringLen; ArrayList<Bundle> actions = rule.getParcelableArrayList("ACTIONS"); if (actions != null) { Log.d("TAG", "\n Actions->"); for (Bundle bAction : actions) { String type = bAction.getString("type"); Object param_1 = bAction.get("action_param_1"); Object param_2 = bAction.get("action_param_2"); Object param_3 = bAction.get("action_param_3"); strFinalResult += "\n type:" + type; if (param_1 != null && param_1 instanceof String) { strFinalResult += "\n param_1:" + param_1; } if (param_2 != null && param_2 instanceof String) { strFinalResult += "\n param_2:" + param_2; } if (param_3 != null && param_3 instanceof String) { strFinalResult += "\n param_3:" + param_3; } } } ArrayList<Bundle> devices = rule.getParcelableArrayList("DEVICES"); if (devices != null) { Log.d("TAG", "\n Devices->"); for (Bundle device : devices) { String type = device.getString("device_id"); Object param_1 = device.get("enabled"); Object param_2 = device.get("alldecoders"); Object param_3 = device.get("all_label_ids"); strFinalResult += "\n Device ID:" + type; if (param_1 != null && param_1 instanceof String) { strFinalResult += "\n Enabled:" + param_1; } if (param_2 != null && param_2 instanceof String) { strFinalResult += "\n All decoders:" + param_2; } if (param_3 != null && param_3 instanceof String) { strFinalResult += "\n All labelids:" + param_3; } } } ArrayList<Bundle> decoders = rule.getParcelableArrayList("DECODERS"); if (decoders != null) { strFinalResult += "\n Decoders->"; for (Bundle decoder : decoders) { String deviceID = decoder.getString("device_id"); String decoderEnabled = decoder.getString("enabled"); String decoderID = decoder.getString("decoder"); strFinalResult += "\n Device ID:" + deviceID; strFinalResult += "\n Decoder Enabled:" + decoderEnabled; strFinalResult += "\n Decoder ID:" + decoderID; } } ArrayList<Bundle> labelIDs = rule.getParcelableArrayList("LABEL_IDS"); if (labelIDs != null) { strFinalResult += "\n LabelIDs->"; for (Bundle labelID : labelIDs) { String deviceID = labelID.getString("device_id"); String lblEnabled = labelID.getString("enabled"); String lblID = labelID.getString("label_id"); strFinalResult += "\n Device ID:" + deviceID; strFinalResult += "\n Label Enabled:" + lblEnabled; strFinalResult += "\n Label ID:" + lblID; } } } } } } else if (pluginName != null && pluginName.equalsIgnoreCase("TOKEN")) { strFinalResult += "\nPlugin " + configBundle.getString("OUTPUT_PLUGIN_NAME") + " TOKEN Settings\n"; Set<String> keys2 = configBundle.keySet(); for (String key2 : keys2) { if (!key2.equalsIgnoreCase("PARAM_LIST")) { } else { Bundle params = configBundle.getBundle("PARAM_LIST"); Set<String> keys3 = params.keySet(); for (String key3 : keys3) { if (key3.equalsIgnoreCase("token_order")) { strFinalResult += "\n" + key3 + ": token_order\n"; ArrayList<Bundle> tokenOrderList = params.getParcelableArrayList("token_order"); int order = 0; for (Bundle b : tokenOrderList) { strFinalResult += "\t" + order + ". " + b.getString("name") + ": " + b.getString("enabled") + "\n"; order++; } } else { strFinalResult += "\n" + key3 + ": " + params.get(key3); } } } } strFinalResult += "\n"; } else if (pluginName != null && pluginName.equalsIgnoreCase("BDF")) { strFinalResult += "\n\nPlugin " + configBundle.getString("OUTPUT_PLUGIN_NAME") + " BDF Settings\n"; Set<String> keys2 = configBundle.keySet(); for (String key2 : keys2) { if (!key2.equalsIgnoreCase("PARAM_LIST")) { } else { Bundle params = configBundle.getBundle("PARAM_LIST"); Set<String> keys3 = params.keySet(); for (String key3 : keys3) { strFinalResult += "\n" + key3 + ": " + params.get(key3); } } } strFinalResult += "\n"; } else { Set<String> keys2 = configBundle.keySet(); if (keys2.size() > 0) { if (configBundle.getString("PLUGIN_NAME") != null) strFinalResult += "\nPlugin " + configBundle.getString("PLUGIN_NAME") + " Settings\n"; for (String key2 : keys2) { if (key2.equalsIgnoreCase("PARAM_LIST")) { Bundle params = configBundle.getBundle("PARAM_LIST"); Set<String> keys3 = params.keySet(); for (String key3 : keys3) { if (key3.equalsIgnoreCase("simulscan_template_params")) { Bundle simulscan_template_params = params.getBundle("simulscan_template_params"); if (simulscan_template_params != null) { strFinalResult += "\n\tDynamic template params"; for (String template_param : simulscan_template_params.keySet()) { strFinalResult += "\n\t\t" + template_param + ": " + simulscan_template_params.get(template_param); } } } else { strFinalResult += "\n\t" + key3 + ": " + params.get(key3); } } } } } strFinalResult += "\n"; } } } else if (key.equalsIgnoreCase("APP_LIST")) { strFinalResult += "\n"; ArrayList<Bundle> appList = resultGetConfig.getParcelableArrayList("APP_LIST"); if (appList == null) { strFinalResult += "\nProfile information is not found for " + profileName; } else if (appList.size() == 0) { Log.d("TAG", "Profile " + profileName + " has no associated information"); strFinalResult += "\n" + "Profile " + profileName + " has no associated information"; } else { strFinalResult += "\nAPP LIST\n\n"; for (Bundle b1 : appList) { strFinalResult += "\n" + b1.getString("PACKAGE_NAME") + ": " + b1.getStringArrayList("ACTIVITY_LIST"); } } strFinalResult += "\n"; } else if (key.equalsIgnoreCase("DCP")) { strFinalResult += "\n"; Bundle dcpSettings = resultGetConfig.getBundle("DCP"); if (dcpSettings == null) { strFinalResult += "\nDCP Settings are not found for " + profileName; } else { strFinalResult += "\nDCP Settings"; for (String dcpKey : dcpSettings.keySet()) { strFinalResult += "\n\t\t" + dcpKey + ": " + dcpSettings.getString(dcpKey); } } strFinalResult += "\n"; } if (key.equalsIgnoreCase("RESULT_CODE")) { strFinalResult += "\nRESULT_CODE: " + resultGetConfig.getString("RESULT_CODE"); ; } } Log.d("TAG", "#IntentApp#\n\nGet config info received\n" + strFinalResult); } } } };

获取 IP 输出

// Get Internet Protocol Output public void getConfig() { Bundle bMain = new Bundle(); bMain.putString("PROFILE_NAME", "Profile007"); Bundle bConfig = new Bundle(); bConfig.putString("PLUGIN_NAME", "IP"); bMain.putBundle("PLUGIN_CONFIG", bConfig); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.GET_CONFIG", bMain); this.sendBroadcast(i); } private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); String strFinalResult = ""; String command = intent.getStringExtra("COMMAND"); String commandidentifier = intent.getStringExtra("COMMAND_IDENTIFIER"); String result = intent.getStringExtra("RESULT"); Bundle bundle = new Bundle(); String resultInfo = ""; if (action.equals("com.symbol.datawedge.api.RESULT_ACTION")) { if (intent.hasExtra("RESULT_INFO")) { bundle = intent.getBundleExtra("RESULT_INFO"); Set<String> keys = bundle.keySet(); for (String key : keys) { String val = bundle.getString(key); if(val == null) { if(bundle.getStringArray(key) != null) { val=""; for (String s : bundle.getStringArray(key)) { val += "" + s + "\n"; } } } resultInfo += key + ": " + val + "\n"; } } else if (intent.hasExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG")) { Bundle resultGetConfig = intent.getBundleExtra("com.symbol.datawedge.api.RESULT_GET_CONFIG"); Set<String> keys = resultGetConfig.keySet(); String profileName = resultGetConfig.getString("PROFILE_NAME"); for (String key : keys) { if (key.equalsIgnoreCase("PLUGIN_CONFIG")) { ArrayList<Bundle> bundleArrayList = resultGetConfig.getParcelableArrayList("PLUGIN_CONFIG"); for (Bundle configBundle : bundleArrayList) { strFinalResult += "\nPlugin " + configBundle.getString("PLUGIN_NAME") + " Settings\n"; for (String configBundleKey : configBundle.keySet()) { if (configBundleKey.equalsIgnoreCase("PARAM_LIST")) { Bundle params = configBundle.getBundle("PARAM_LIST"); for (String paramKey : params.keySet()) { strFinalResult += "\n\t" + paramKey + ": " + params.get(paramKey); } } } strFinalResult += "\n"; } } } Log.d("TAG","#IntentApp#\n\nGet config info received\n" + strFinalResult); } if (command != null) { if (command.equalsIgnoreCase("com.symbol.datawedge.api.SET_CONFIG")) { Log.d("TAG","#IntentApp# \n\nSetConfig status received: " + result + "\nResultInfo: " + resultInfo); } } } } };

另请参阅

Zebra 支持中心 | 集成商指南、产品手册、软件下载和支持

LaunchPad | Zebra 开发人员社区

Intent | Android 开发人员

Intent 和 Intent 过滤器 | Android 开发人员

Android Intent | 教程