# Android 扫描服务接口设置 > 江苏东大集成电路系统工程技术有限公司 > www.seuic.com ![SEUIC 东集 Logo 图片占位符] > **强烈建议修改广播名称** ## 修订记录 | 版本号 | 修订日期 | 修订内容 | 修订人员 | | --- | --- | --- | --- | | 1.0 | 2015/09/21 | 建立本文档 | 徐良伟 | | 1.1 | 2016/11/07 | 增加过滤条码首尾空格选项 | 罗涛 | | 1.2 | 2017/03/20 | 扫描特殊功能实现演示 | 罗涛 | | 1.3 | 2017/05/31 | 加入启用/禁用扫描头以及过滤不可见字符广播接口介绍 | 罗涛 | | 1.4 | 2017/07/18 | 修正条码参数设置广播接口 | 罗涛 | | 1.5 | 2018/4/3 | 加入开始/停止扫描广播接口 | 罗涛 | ## 目录 - 概述 - 硬件平台 - 软件平台 - 适用对象 - 扫描服务应用设置 - 扫描声音开关 - 振动开关 - 连续扫描开关 - 时间间隔设置 - 条码前缀参数设置 - 条码后缀参数设置 - 开机自启动设置 - 条码结束符设置 - 条码发送方式 - 条码的广播设置 - 过滤首尾空格开关 - 条码参数设置 - 启用/禁用扫描头 - 过滤不可见字符 - 开始扫描 - 停止扫描 - 扫描特殊功能实现 - 持续出光模式设置 --- # 概述 东集提供的设备上内置了扫描服务,也提供了相应的设置软件。但部分客户有在自己的应用中定制扫描服务的需求。本文档介绍了如何通过接口来设置扫描服务的部分选项,以便帮助用户更灵活地使用我们的设备。 ## 硬件平台 SDK 适用于以下终端设备: - D500 - D510 - D330S - D500P - D510P - D330P - D700 - D500F - D700P 具体使用范围在函数接口说明中指明,若无指明表示都支持。 ## 软件平台 SDK 基于 Android 4.3、Android 4.4、Android 5.1、Android 7.1 版本,支持 Eclipse、Android Studio 开发工具。 ## 适用对象 希望在自己的应用中定制扫描服务的开发人员。 --- # 扫描服务应用设置 扫描服务应用设置支持以下功能的设置: - 扫描声音开关 - 振动开关 - 连续扫描开关 - 时间间隔设置 - 条码前缀参数设置 - 条码后缀参数设置 - 开机自启动设置 - 条码结束符设置 - 条码发送方式 - 条码的广播设置 - 过滤条码首尾空格开关 - 条码参数设置 - 启用/禁用扫描头 - 过滤不可见字符 - 开始扫描 - 停止扫描 **版本需求:** 扫描应用 1.0.67 及以后,部分设置 1.0.69 及以后。 - **1.0.67 支持** - 扫描声音开关 - 振动开关 - 开机自启动设置 - 条码结束符设置 - 条码发送方式 - 条码的广播设置 - 启用/禁用扫描头 - **1.0.69 支持** - 连续扫描开关 - 时间间隔设置 - 条码前缀参数设置 - 条码后缀参数设置 - 条码参数设置 - **1.1.3 支持** - 过滤条码首尾空格开关 - 过滤不可见字符 > **备注:** 支持在一条广播中进行多项设置。 ## 扫描声音开关 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `sound_play` | | 取值 | boolean 型,true 或 false | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("sound_play", true); sendBroadcast(intent); ``` ## 振动开关 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `viberate` | | 取值 | boolean 型,true 或 false | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("viberate", false); sendBroadcast(intent); ``` ## 连续扫描开关 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `scan_continue` | | 取值 | boolean 型,true 或 false | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("scan_continue", true); sendBroadcast(intent); ``` ## 时间间隔设置 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `interval` | | 取值 | int 型 | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("interval", 3000); sendBroadcast(intent); ``` ## 条码前缀参数设置 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `prefix` | | 取值 | String 型,默认为 `" "` | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("prefix", ""); sendBroadcast(intent); ``` ## 条码后缀参数设置 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `suffix` | | 取值 | String 型,默认为 `" "` | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("suffix", ""); sendBroadcast(intent); ``` ## 开机自启动设置 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `boot_start` | | 取值 | boolean 型,true 或 false | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("boot_start", true); sendBroadcast(intent); ``` ## 条码结束符设置 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `endchar` | | 取值 | 在条码后面附加的结束符,字符串类型,注意大小写,支持以下几种:
 `"ENTER"`:回车
 `"TAB"`:TAB
 `"SPACE"`:空格
 `"NONE"`:无结束符 | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("endchar", "ENTER"); sendBroadcast(intent); ``` ## 结束符以 Enter 键发送 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `end_char_on_emu` | | 取值 | 结束符以 Enter 键发送:模拟按键模式下 | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("end_char_on_emu", true); sendBroadcast(intent); ``` ## 条码发送方式 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `barcode_send_mode` | | 取值 | 扫描服务扫描到条码后的发送方式,字符串类型,注意大小写,支持以下几种:
 `"FOCUS"`:焦点录入
 `"BROADCAST"`:广播
 `"EMUKEY"`:模拟按键
 `"CLIPBOARD"`:剪贴板 | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("barcode_send_mode", "BROADCAST"); sendBroadcast(intent); ``` ## 条码的广播设置 **条码广播名称** | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `action_barcode_broadcast` | | 取值 | 字符串类型,默认是:`"com.android.server.scannerservice.broadcast"` | **条码键值名称** | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `key_barcode_broadcast` | | 取值 | 字符串类型,默认是:`"scannerdata"` | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("action_barcode_broadcast", "com.android.server.scannerservice.broadcast"); intent.putExtra("key_barcode_broadcast", "scannerdata"); sendBroadcast(intent); ``` ## 过滤首尾空格开关 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `filter_prefix_suffix_blank` | | 取值 | boolean 型,true 或 false | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("filter_prefix_suffix_blank", true); sendBroadcast(intent); ``` ## 条码参数设置 | 项目 | 内容 | | --- | --- | | action | `com.seuic.scanner.action.PARAM_SETTINGS` | | extra1 | `number` | | 取值 | int 型 | | extra2 | `value` | | 取值 | int 型 | > 有关扫描参数详情请见:[Android 扫描接口文档(1.0)](./Android扫描接口文档.md) **示例:** ```java Intent intent = new Intent("com.seuic.scanner.action.PARAM_SETTINGS"); intent.putExtra("number", 0x01); intent.putExtra("value", 30); sendBroadcast(intent); ``` ## 启用/禁用扫描头 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.ENABLED` | | extra | `enabled` | | 取值 | boolean 型,true 或 false | **示例:** 启用扫描头: ```java Intent intent = new Intent("com.android.scanner.ENABLED"); intent.putExtra("enabled", true); sendBroadcast(intent); ``` 禁用扫描头: ```java Intent intent = new Intent("com.android.scanner.ENABLED"); intent.putExtra("enabled", false); sendBroadcast(intent); ``` ## 过滤不可见字符 | 项目 | 内容 | | --- | --- | | action | `com.android.scanner.service_settings` | | extra | `filter_invisible_chars` | | 取值 | boolean 型,true 或 false | **示例:** ```java Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("filter_invisible_chars", true); sendBroadcast(intent); ``` ## 开始扫描 | 项目 | 内容 | | --- | --- | | action | `com.scan.onStartScan` | **示例:** 开始出光扫描: ```java Intent intent = new Intent("com.scan.onStartScan"); sendBroadcast(intent); ``` ## 停止扫描 | 项目 | 内容 | | --- | --- | | action | `com.scan.onEndScan` | **示例:** 停止出光扫描: ```java Intent intent = new Intent("com.scan.onEndScan"); sendBroadcast(intent); ``` ## 相关常量定义 ```java private final String TYPE_KEYUP_TO_STOP_SCAN = "keyup_to_stop_scan"; // 抬起停止扫描 private final String TYPE_ENDCHAR_ON_EMU = "end_char_on_emu"; // 结束符以模拟按键方式发送 private final String TYPE_ENTER_EVENT = "end_event"; // 默认广播时条码后添加回车事件 private final String TYPE_FILTER_INVISIBLE_CHARS = "filter_invisible_chars"; // 过滤不可见字符 private final String TYPE_FILTER_PREFIX_SUFFIX_BLANK = "filter_prefix_suffix_blank"; // 过滤首尾空格 ``` --- # 扫描特殊功能实现 ## 持续出光模式设置 **示例代码:** ```java // 将连续扫描打开 Intent intent = new Intent("com.android.scanner.service_settings"); intent.putExtra("scan_continue", true); sendBroadcast(intent); // 设置条码参数持续出光为开 Intent intentParam = new Intent("com.android.scanner.PARAM_SETTINGS"); intent.putExtra("number", 0x0c); intent.putExtra("value", 1); sendBroadcast(intentParam); ```