启用 DataWedge

DataWedge 7.4

ENABLE_DATAWEDGE

布尔值用于在设备上启用 (true) 或禁用 (false) DataWedge。

函数原型

Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.ENABLE_DATAWEDGE", <value>);

参数

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

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

布尔 <值>:True 或 False

结果代码

如果应用程序包括 Intent 额外项 RECEIVE_RESULTCOMMAND_IDENTIFIER 以使应用程序能够使用 DataWedge 结果 Intent 机制获取结果,则 DataWedge 返回以下错误代码。请参阅以下示例

  • DATAWEDGE_ALREADY_ENABLED - FAILURE
  • DATAWEDGE_ALREADY_DISABLED - FAILURE

有关更多信息,另请参阅结果代码指南

返回值

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

$ adb logcat -s DWAPI

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

示例代码

Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.ENABLE_DATAWEDGE", false); this.sendBroadcast(i);

生成和接收结果

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

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

// send the intent Intent i = new Intent(); i.setAction(ACTION); i.putExtra("com.symbol.datawedge.api.CREATE_PROFILE", "Profile1"); // request and identify the result code i.putExtra("SEND_RESULT","true"); 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(); };

设置/获取结果代码

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

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

// send the intent Intent i = new Intent(); i.setAction(ACTION); i.putExtra("com.symbol.datawedge.api.CREATE_PROFILE", "Profile1"); // request and identify the result code i.putExtra("SEND_RESULT","true"); 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(); };

另请参阅

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

LaunchPad | Zebra 开发人员社区

Intent | Android 开发人员

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

Android Intent | 教程