新闻资讯

斑马PDA的安卓Datawedge API扫描开发接口

2025-03-19 09:58:03


工业手持PDA的领导者斑马技术

在Apk中如何快速的输入数据

传统的光标位置,键盘仿真输入数据

较容易替代,

遇到复杂问题不容易解决,

例如扫描前清空输入框,

或是扫描数据全选的需求

ZEBRA 也支持更加安全可靠

功能更加丰富的Intent 广播模式

将扫描数据送入输入框


DataWedge 功能强大,提高生产力

DataWedge是在所有Zebra Android设备上运行的服务

可被其他应用程序用来控制数据捕获,

而无需直接访问DataWedge UI。

可以控制大大方便DataWedge的数据捕获

参考《DataWedge API  接口说明》

如果有异议以官网内容为准

本手册内容原版信息

https://techdocs.zebra.com/datawedge/8-2/guide/api/

image.png

相关官方开发样例和源码参考

https://techdocs.zebra.com/datawedge/8-2/guide/samples/

image.png

或参考Github网站 

 https://github.com/Zebra/techdocs-archive

image.png


DataWedge  配置架构

image.png

通过指定不同的Bundle,我们可以实现不同框架下配置属性的快速修改

DataWedge 调用流程

1. 创建一个配置文件。

如果未创建和分配任何配置文件,则DataWedge将使用Profile0,但我们建议为你的apk单独创建Profile进行管理

//创建一个独立的profile名字为 zebraIntent

private void createProfile() {

 Intent i = new Intent(); 

i.setAction("com.symbol.datawedge.api.ACTION");

 i.putExtra("com.symbol.datawedge.api.CREATE_PROFILE", "zebraIntent");

 this.sendBroadcast(i); 

}

  • 2.  目标应用程序关联新建的profile

一个Activity不能关联到两个profile。应用运行中可以通过使用SwitchProfile来切换不同的profile来实现不同的配置。

/* * DataWedge设置关联应用程序zebrascan 到profile文件zebraIntent */

public void setAppListConfiguration() 

{

Bundle bMain = new Bundle();

Bundle app1 = new Bundle();     

app1.putString("PACKAGE_NAME","com.example.zebrascan");

app1.putStringArray("ACTIVITY_LIST", new String[]{"*"});  

bMain.putParcelableArray("APP_LIST", new Bundle[]{app1});

bMain.putString("PROFILE_NAME","zebraIntent");

bMain.putString("PROFILE_ENABLED","true");

bMain.putString("CONFIG_MODE","CREATE_IF_NOT_EXIST");   

 Intent i = new Intent();

i.setAction("com.symbol.datawedge.api.ACTION");

i.putExtra("com.symbol.datawedge.api.SET_CONFIG", bMain);

i.putExtra("SEND_RESULT", "true");

i.putExtra("COMMAND_IDENTIFIER", "APP_LIST");

this.sendBroadcast(i);

}

也可以通过修改profile来实现设置的切换,例如下面通过修改aim_type 的值,实现按键“连续扫描”的的设置。我们可以在 Set Config 网页中,查询详细的设置项说明。(此节为可选说明)

/* * DataWedge设置连续扫描 Intent输出  */

public void setContinuousConfiguration()

 {

Bundle bMain = new Bundle();

Bundle bConfig = new Bundle();

Bundle bParams = new Bundle();

bParams.putString("scanner_selection","auto");

bParams.putString("aim_type","5"); 

//AIM_TYPE 0单一扫描,5连续扫描

bConfig.putBundle("PARAM_LIST", bParams);

bConfig.putString("PLUGIN_NAME","BARCODE");

bConfig.putString("RESET_CONFIG","true");

bMain.putBundle("PLUGIN_CONFIG", bConfig);

bMain.putString("PROFILE_NAME","zebraIntent");

bMain.putString("PROFILE_ENABLED","true");

bMain.putString("CONFIG_MODE","CREATE_IF_NOT_EXIST");

Intent i = new Intent();

i.setAction("com.symbol.datawedge.api.ACTION");

i.putExtra("com.symbol.datawedge.api.SET_CONFIG",bMain);

i.putExtra("SEND_RESULT", "true");

i.putExtra("COMMAND_IDENTIFIER", "BARCODE_SETTING_API");

this.sendBroadcast(i);

}


3. DataWedge设置并启用Intent输出

设置“intent_output_enabled” 生效,此profile启用intent传递数据。

定义Intent

操作字串"com.symbol.mybroadcast",

类别字串"com.symbol.category.DEFAULT"。

/* * DataWedge设置连续扫描 Intent输出  */

public void setContinuousConfiguration()

 {

Bundle bMain = new Bundle();

Bundle bConfig = new Bundle();

Bundle bParams = new Bundle();

bParams.putString("scanner_selection","auto");

bParams.putString("aim_type","5"); 

//AIM_TYPE 0单一扫描,5连续扫描

bConfig.putBundle("PARAM_LIST", bParams);

bConfig.putString("PLUGIN_NAME","BARCODE");

bConfig.putString("RESET_CONFIG","true");


bMain.putBundle("PLUGIN_CONFIG", bConfig);

bMain.putString("PROFILE_NAME","zebraIntent");

bMain.putString("PROFILE_ENABLED","true");

bMain.putString("CONFIG_MODE","CREATE_IF_NOT_EXIST");

Intent i = new Intent();

i.setAction("com.symbol.datawedge.api.ACTION");

i.putExtra("com.symbol.datawedge.api.SET_CONFIG",bMain);

i.putExtra("SEND_RESULT", "true");

i.putExtra("COMMAND_IDENTIFIER", "BARCODE_SETTING_API");

this.sendBroadcast(i);

}

4. 设置 intent 的操作字串

com.symbol.datawedge.data_string 是通过Intent捕获到的Datawedge返回的条码数据(字串格式)名称,无法修改请注意。

//定义Intent的操作字串

private String INTENT_ACTION = "com.symbol.mybroadcast";

//定义Intent的类别字串

private String INTENT_CATEGORY = "com.symbol.category.DEFAULT";

//API中定义,通过Intent捕获到的Datawedge返回的条码数据(字串格式)名称

private String DATA_STRING_TAG = "com.symbol.datawedge.data_string";

        其他       


将DataWedge Profile的添加和配置放在程序中,通过API来实现,这样一方面可以避免手动配置设备的繁琐工作,也可以避免手动设置失误可能带来的错误。


无论是使用键盘输出,还是Intent输出,建议用户开发人员不要直接使用Profile0,建立并关联自己的配置文件,避免其他程序的操作造成无法预测的影响。


感谢斑马SE:Max  & Wangjian 的指导

客服