Intent 结果代码

DataWedge 7.4

概述

在 DataWedge 6.5 中引入。

Intent 结果代码传递关于 DataWedge API 命令的状态信息,以帮助开发人员确定数据流及其业务逻辑的功能。结果代码与 DataWedge 6.5 中引入的一些 API 一起实施,并已将其添加到之前存在的诸多 API。

使用 RESULT_INFO Intent 机制访问结果代码;如果应用程序包含如下面原型所示的 Intent 额外项 SEND_RESULTCOMMAND_IDENTIFIER,则该机制会返回错误代码。有关显示如何注册应用程序以接收结果代码的代码,请参阅下面的示例部分

函数原型

// send the intent Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.CREATE_PROFILE", "Profile007"); // request and identify the result code i.putExtra("SEND_RESULT","LAST_RESULT"); //Supported values: NONE, LAST_RESULT, COMPLETE_RESULT i.putExtra("COMMAND_IDENTIFIER","123456789"); this.sendBroadcast(i);

参数

RESULT [字符串]:操作成功/失败

COMMAND [字符串]:所接收 Intent 命令的名称

COMMAND_IDENTIFIER [字符串]:用于将结果链接至特定命令的可选参数

SEND_RESULT [字符串]:在 DataWedge 7.1 或更高版本中接受以下值。(低于 7.1 的 DataWedge 版本只接受 TRUE 和 FALSE)。

  • NONE:没有结果返回到应用程序。(对于低于 7.1 的 DataWedge 版本,这相当于 FALSE)。
  • LAST_RESULT:发送最后执行的模块的结果信息。如果用户发送多个插件,则返回最后发送的插件的结果信息。(对于低于 DataWedge 7.1 的版本,这相当于 TRUE)。例如:按顺序发送 BARCODE、SIMULSCAN 和 SERIAL 插件。应用程序收到的结果信息只是从 SERIAL 插件返回的结果。
  • COMPLETE_RESULT:如果发送了多个插件,则返回每个插件的结果信息列表。

RESULT_INFO [捆绑包]:可以包含以下任何字段,具体取决于所使用的 API:

  • PREVIOUS_DEFAULT_PROFILE - 在设置新的默认配置文件时,指定上一个默认配置文件

  • PREVIOUS_PROFILE - 在切换和重命名配置文件时,在该参数中指定上一个配置文件

  • PROFILE_NAME - 始终是当前或下一个配置文件名称

  • RESULT_CODE - 列表中显示其中一个可能的结果代码

  • SOURCE_PROFILE_NAME - 克隆配置文件时,指定源配置文件

  • RESULT_CODE - 仅针对 FAILURE 返回。可以包含以下任何字段,具体取决于所使用的 API:

    • APP_ALREADY_ASSOCIATED - 尝试关联已经与另一配置文件关联的应用程序
    • BUNDLE_EMPTY - 捆绑包不包含任何数据
    • DATAWEDGE_ALREADY_DISABLED - 尝试禁用已禁用的 DataWedge
    • DATAWEDGE_ALREADY_ENABLED - 尝试启用已启用的 DataWedge
    • DATAWEDGE_DISABLED - 当 DataWedge 处于禁用状态时,尝试执行操作
    • INPUT_NOT_ENABLED - 当条码或 SimulScan 插件处于禁用状态时,尝试获取数据
    • OPERATION_NOT_ALLOWED - 尝试重命名或删除受保护的配置文件或将应用程序与 Profile0 关联
    • PARAMETER_INVALID - 传递的参数为空、为 null 或无效
    • PLUGIN_NOT_SUPPORTED - 尝试配置不受 DataWedge Intent API 支持的插件
    • PLUGIN_BUNDLE_INVALID - 传递的插件参数捆绑包为空或包含的信息不足
    • PROFILE_ALREADY_EXISTS - 尝试使用已存在的名称创建、克隆或重命名配置文件
    • PROFILE_ALREADY_SET - 尝试将默认配置文件设置为默认配置文件
    • PROFILE_DISABLED - 尝试针对已禁用的配置文件执行操作
    • PLUGIN_DISABLED_IN_CONFIG - 已从 DataWedge UI 手动禁用条码插件时,尝试启用或禁用扫描器
    • PROFILE_HAS_APP_ASSOCIATION - 尝试切换到已与另一应用程序关联的配置文件或将其设置为默认配置文件
    • PROFILE_NAME_EMPTY - 尝试配置空的配置文件名称
    • PROFILE_NOT_FOUND - 尝试针对不存在的配置文件执行操作
    • SCANNER_ALREADY_DISABLED - 尝试禁用已禁用的扫描器
    • SCANNER_ALREADY_ENABLED - 尝试启用已启用的扫描器
    • SCANNER_DISABLE_FAILED - 禁用扫描器时发生异常
    • SCANNER_ENABLE_FAILED - 启用扫描器时发生异常
    • UNKNOWN - 发生未确定的错误

返回值

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

$ adb logcat -s DWAPI

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

示例代码

//SENDING THE INTENT Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.RESTORE_CONFIG", ""); this.sendBroadcast (i);

生成和接收结果代码

命令和配置 Intent 参数决定是否发送结果代码(默认情况下处于禁用状态)。使用 SEND_RESULT 时,COMMAND_IDENTIFIER 用于将结果代码与起源 Intent 进行匹配。这些参数的示例用法如下所示。

注意:修改此通用代码以与要使用的 API 匹配

// send the intent Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.CREATE_PROFILE", "Profile007"); // request and identify the result code i.putExtra("SEND_RESULT","LAST_RESULT"); //Supported values: NONE, LAST_RESULT, COMPLETE_RESULT i.putExtra("COMMAND_IDENTIFIER","123456789"); this.sendBroadcast(i); // register to receive the result public void onReceive(Context context, Intent intent){ 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: " +resultInfo + "\n" + "CID:"+commandidentifier; Toast.makeText(context, text, Toast.LENGTH_LONG).show(); };

生成和接收多个模块(插件、APP_LIST 和 Data Capture Plus)的结果代码

public void setConfig() { // SetConfig [Start] Bundle bMain = new Bundle(); Bundle bConfigIntent = new Bundle(); Bundle bParamsIntent = new Bundle(); bParamsIntent.putString("intent_output_enabled", "true"); bParamsIntent.putString("intent_action", "com.symbol.dwudiusertokens.udi"); bParamsIntent.putString("intent_category", "zebra.intent.dwudiusertokens.UDI"); bParamsIntent.putInt("intent_delivery", 5); //Use "0" for Start Activity, "1" for Start Service, "2" for Broadcast, "3" for start foreground service bConfigIntent.putString("PLUGIN_NAME", "INTENT"); bConfigIntent.putString("RESET_CONFIG", "false"); bConfigIntent.putBundle("PARAM_LIST", bParamsIntent); Bundle bConfigSimulScan = new Bundle(); Bundle bParamsSimulScan = new Bundle(); bParamsSimulScan.putString("simulscan_input_enabled", "true"); bParamsSimulScan.putString("simulscan_input_source", "Imager"); //Supported values: Camera, Imager, Default bParamsSimulScan.putString("simulscan_region_separator", "TAB"); //Supported Values:None, TAB, CR, LF, NONE bParamsSimulScan.putString("simulscan_log_dir", "/storage/zebra/intent/"); bParamsSimulScan.putString("simulscan_enable_timestamp", "true"); Bundle templateParamsBundle = new Bundle(); templateParamsBundle.putString("dynamic_quantity", "99"); bParamsSimulScan.putString("simulscan_template", "UserDefinedQuantity.xml"); // Ex: UserDefinedQuantity.xml, Default - BankCheck.xml, Default - Barcode 1.xml, Default - Barcode 10.xml, Default - Barcode 2.xml, Default - Barcode 4.xml, Default - Barcode 5.xml, Default - BookNumber.xml, Default - DocCap + Optional Barcode.xml, Default - DocCap + Required Barcode.xml, Default - TravelDoc.xml, Default - Unstructured Multi-Line.xml, Default - Unstructured Single Line.xml bParamsSimulScan.putBundle("simulscan_template_params",templateParamsBundle); bConfigSimulScan.putString("PLUGIN_NAME", "SIMULSCAN"); bConfigSimulScan.putString("RESET_CONFIG", "false"); bConfigSimulScan.putBundle("PARAM_LIST", bParamsSimulScan); Bundle bConfigBarcode = new Bundle(); Bundle bParamsBarcode = new Bundle(); bParamsBarcode.putString("scanner_selection","auto"); bParamsBarcode.putString("scanner_input_enabled","true"); bConfigBarcode.putString("PLUGIN_NAME", "BARCODE"); bConfigBarcode.putString("RESET_CONFIG", "false"); bConfigBarcode.putBundle("PARAM_LIST", bParamsBarcode); Bundle bConfigMSR = new Bundle(); Bundle bParamsMSR = new Bundle(); bParamsMSR.putString("msr_input_enabled", "true"); bConfigMSR.putString("PLUGIN_NAME", "MSR"); bConfigMSR.putString("RESET_CONFIG", "false"); bConfigMSR.putBundle("PARAM_LIST", bParamsMSR); Bundle bConfigIPOutput = new Bundle(); Bundle bParamsIPOutput = new Bundle(); bParamsIPOutput.putString("ip_output_enabled", "true"); bParamsIPOutput.putString("ip_output_ip_wedge_enabled", "false"); bParamsIPOutput.putString("ip_output_protocol", "UDP"); //Supported Values: TCP: UDP bParamsIPOutput.putString("ip_output_address", "192.168.0.1"); //Supported Values : IP Address format bParamsIPOutput.putString("ip_output_port", "55555"); //Supported Values : 1 - 65535 bConfigIPOutput.putString("PLUGIN_NAME", "IP"); bConfigIPOutput.putString("RESET_CONFIG", "false"); bConfigIPOutput.putBundle("PARAM_LIST", bParamsIPOutput); Bundle bConfigToken = new Bundle(); Bundle bParamsToken = new Bundle(); bParamsToken.putString("send_tokens_option", "BARCODES_TOKENS"); // Supported Values: DISABLED, TOKENS, BARCODES_TOKENS bParamsToken.putString("token_separator", "LF"); //Supported Values:None, TAB, CR, LF, NONE bParamsToken.putString("multibarcode_separator", "LF"); //Supported Values:None, TAB, CR, LF, NONE Bundle tokenOrder_manufacturing_date_original = new Bundle(); tokenOrder_manufacturing_date_original.putString("name","manufacturing_date_original"); tokenOrder_manufacturing_date_original.putString("enabled","true"); Bundle tokenOrder_expiration_date_original = new Bundle(); tokenOrder_expiration_date_original.putString("name","expiration_date_original"); tokenOrder_expiration_date_original.putString("enabled","true"); Bundle tokenOrder_di = new Bundle(); tokenOrder_di.putString("name","di"); tokenOrder_di.putString("enabled","true"); Bundle tokenOrder_lot_number = new Bundle(); tokenOrder_lot_number.putString("name","lot_number"); tokenOrder_lot_number.putString("enabled","true"); Bundle tokenOrder_serial_number = new Bundle(); tokenOrder_serial_number.putString("name","serial_number"); tokenOrder_serial_number.putString("enabled","true"); Bundle tokenOrder_mpho_lot_number = new Bundle(); tokenOrder_mpho_lot_number.putString("name","mpho_lot_number"); tokenOrder_mpho_lot_number.putString("enabled","true"); Bundle tokenOrder_donation_id = new Bundle(); tokenOrder_donation_id.putString("name","donation_id"); tokenOrder_donation_id.putString("enabled","true"); Bundle tokenOrder_labeler_identification_code = new Bundle(); tokenOrder_labeler_identification_code.putString("name","labeler_identification_code"); tokenOrder_labeler_identification_code.putString("enabled","true"); Bundle tokenOrder_product_or_catalog_number = new Bundle(); tokenOrder_product_or_catalog_number.putString("name","product_or_catalog_number"); tokenOrder_product_or_catalog_number.putString("enabled","true"); Bundle tokenOrder_unit_of_measure_id = new Bundle(); tokenOrder_unit_of_measure_id.putString("name","unit_of_measure_id"); tokenOrder_unit_of_measure_id.putString("enabled","true"); Bundle tokenOrder_quantity = new Bundle(); tokenOrder_quantity.putString("name","quantity"); tokenOrder_quantity.putString("enabled","false"); ArrayList<Bundle> tokenOrderList = new ArrayList<>(); tokenOrderList.add(tokenOrder_manufacturing_date_original); tokenOrderList.add(tokenOrder_expiration_date_original); tokenOrderList.add(tokenOrder_lot_number); tokenOrderList.add(tokenOrder_di); tokenOrderList.add(tokenOrder_serial_number); tokenOrderList.add(tokenOrder_mpho_lot_number); tokenOrderList.add(tokenOrder_donation_id); tokenOrderList.add(tokenOrder_labeler_identification_code); tokenOrderList.add(tokenOrder_product_or_catalog_number); tokenOrderList.add(tokenOrder_unit_of_measure_id); tokenOrderList.add(tokenOrder_quantity); bParamsToken.putParcelableArrayList("token_order", tokenOrderList); bConfigToken.putString("PLUGIN_NAME", "TOKEN"); bConfigToken.putString("OUTPUT_PLUGIN_NAME","IP"); bConfigToken.putString("RESET_CONFIG", "true"); bConfigToken.putBundle("PARAM_LIST", bParamsToken); ArrayList<Bundle> bundlePluginConfig = new ArrayList<>(); bundlePluginConfig.add(bConfigIntent); bundlePluginConfig.add(bConfigBarcode); bundlePluginConfig.add(bConfigSimulScan); bundlePluginConfig.add(bConfigMSR); bundlePluginConfig.add(bConfigIPOutput); bundlePluginConfig.add(bConfigToken); bMain.putParcelableArrayList("PLUGIN_CONFIG", bundlePluginConfig); //AppList[Start] Bundle bundleApp1 = new Bundle(); bundleApp1.putString("PACKAGE_NAME", "com.symbol.emdk.simulscansample1"); bundleApp1.putStringArray("ACTIVITY_LIST", new String[]{ "com.symbol.emdk.simulscansample1.DeviceControl", "com.symbol.emdk.simulscansample1.MainActivity", "com.symbol.emdk.simulscansample1.ResultsActivity", "com.symbol.emdk.simulscansample1.ResultsActivity2", "com.symbol.emdk.simulscansample1.SettingsFragment1"}); Bundle bundleApp2 = new Bundle(); bundleApp2.putString("PACKAGE_NAME", "com.example.intents.datawedgeintent"); bundleApp2.putStringArray("ACTIVITY_LIST", new String[]{ "com.example.intents.datawedgeintent.DeviceControl", "com.example.intents.datawedgeintent.MainActivity", "com.example.intents.datawedgeintent.ResultsActivity", "com.example.intents.datawedgeintent.SettingsFragment1"}); Bundle bundleApp3 = new Bundle(); bundleApp3.putString("PACKAGE_NAME", "com.symbol.pubudu"); bundleApp3.putStringArray("ACTIVITY_LIST", new String[]{"*"}); Bundle bundleApp4 = new Bundle(); bundleApp4.putString("PACKAGE_NAME", "com.symbol.myzebraapp"); bundleApp4.putStringArray("ACTIVITY_LIST", new String[]{"*"}); // ADD APP_LIST BUNDLE(S) INTO THE MAIN BUNDLE bMain.putParcelableArray("APP_LIST", new Bundle[]{ bundleApp1 , bundleApp2 , bundleApp3 , bundleApp4 }); //AppList [End] Bundle bConfigDCP = new Bundle(); Bundle bParamsDCP = new Bundle(); bParamsDCP.putString("dcp_input_enabled", "true"); bParamsDCP.putString("dcp_dock_button_on", "LEFT"); //Supported values: BOTH - Left or Right, LEFT - Left only, RIGHT - Right only bParamsDCP.putString("dcp_start_in", "FULLSCREEN"); //Supported Values: FULLSCREEN, BUTTON, BUTTON_ONLY bParamsDCP.putString("dcp_highest_pos", "10"); //Supported Values: 0 - 100 bParamsDCP.putString("dcp_lowest_pos", "20"); //Supported Values: 0 - 100 bParamsDCP.putString("dcp_drag_detect_time", "501"); //Supported Values: 0 - 1000 bConfigDCP.putString("RESET_CONFIG", "true"); bConfigDCP.putBundle("PARAM_LIST", bParamsDCP); bMain.putBundle("DCP", bConfigDCP); bMain.putString("PROFILE_NAME", "Profile007"); bMain.putString("PROFILE_ENABLED", "true"); bMain.putString("CONFIG_MODE", "CREATE_IF_NOT_EXIST"); Intent iSetConfig = new Intent(); iSetConfig.setAction("com.symbol.datawedge.api.ACTION"); iSetConfig.putExtra("com.symbol.datawedge.api.SET_CONFIG", bMain); iSetConfig.putExtra("SEND_RESULT", "COMPLETE_RESULT"); //Supported values: NONE, LAST_RESULT, COMPLETE_RESULT iSetConfig.putExtra("COMMAND_IDENTIFIER", "INTENT_API"); // SetConfig [End] this.sendBroadcast(iSetConfig); } 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 profileName = intent.getStringExtra("PROFILE_NAME"); String resultInfo = ""; if (action.equals("com.symbol.datawedge.api.RESULT_ACTION")) { if (intent.hasExtra("RESULT_LIST")) { // returns for COMPLETE_RESULT resultInfo += "ProfileName: " + profileName + "\n"; ArrayList<Bundle> result_list = (ArrayList)intent.getSerializableExtra("RESULT_LIST"); for (Bundle bundleResult : result_list) { resultInfo +="\n\n"; Set<String> keys = bundleResult.keySet(); for (String key : keys) { String val = bundleResult.getString(key); if (val == null) { if (bundleResult.getStringArray(key) != null) { val = ""; for (String s : bundleResult.getStringArray(key)) { val += "" + s + "\n"; } } } resultInfo += key + ": " + val + "\n"; } } } else if (intent.hasExtra("RESULT_INFO")) { // returns for LAST_RESULT String result = intent.getStringExtra("RESULT"); Bundle bundle = intent.getBundleExtra("RESULT_INFO"); resultInfo += "Result: " + result + "\n"; 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"; } } if (command != null) { if (command.equalsIgnoreCase("com.symbol.datawedge.api.SET_CONFIG")) { Log.d("TAG", "#IntentApp# \n\nSetConfig status received:\nResultInfo: \n" + resultInfo); } } } } };

注释

  • 结果 Internt 机制不会对扫描器输入参数和 Intent 输出参数执行参数级别验证。例如,任何应用程序都无法验证不再连接的扫描器的各个可能参数。但是,如果配置中的参数值在加载配置文件时无效,则 DataWedge 会使用该参数的默认值。

  • 如果接收到多个模块,DataWedge 将按以下顺序执行 SET_CONFIG 命令。

  1. 插件
  2. APP_LIST
  3. DCP (Data Capture Plus)

另请参阅

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

LaunchPad | Zebra 开发人员社区

Intent | Android 开发人员

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

Android Intent | 教程