如何在MainActivity配置UROVO DT50扫描器键盘模式下接收Intent输出
解决方案:在UROVO DT50上通过DataWedge配置Intent输出(无需手动设置设备)
核心逻辑
UROVO DT50兼容Zebra DataWedge框架,我们可以通过代码创建App专属的DataWedge配置文件,强制扫描器向你的Flutter应用发送Intent输出,完全绕过键盘模式的限制——这个配置仅针对你的App生效,不会改变设备全局设置。
修改你的MainActivity代码
你现有代码已经包含createDataWedgeProfile方法,但需要补充禁用键盘输出的关键配置,确保Intent输出始终优先生效。以下是修改后的完整关键代码:
1. 完善createDataWedgeProfile方法
private fun createDataWedgeProfile(profileName: String) { // 1. 创建DataWedge配置文件 dwInterface.sendCommandString(this, DWInterface.DATAWEDGE_SEND_CREATE_PROFILE, profileName) val profileConfig = Bundle() profileConfig.putString("PROFILE_NAME", profileName) profileConfig.putString("PROFILE_ENABLED", "true") profileConfig.putString("CONFIG_MODE", "UPDATE") // 2. 配置条码扫描插件(保留原有逻辑) val barcodeConfig = Bundle() barcodeConfig.putString("PLUGIN_NAME", "BARCODE") barcodeConfig.putString("RESET_CONFIG", "true") val barcodeProps = Bundle() barcodeConfig.putBundle("PARAM_LIST", barcodeProps) profileConfig.putBundle("PLUGIN_CONFIG", barcodeConfig) // 3. 将配置文件关联到当前App val appConfig = Bundle() appConfig.putString("PACKAGE_NAME", packageName) appConfig.putStringArray("ACTIVITY_LIST", arrayOf("*")) profileConfig.putParcelableArray("APP_LIST", arrayOf(appConfig)) dwInterface.sendCommandBundle(this, DWInterface.DATAWEDGE_SEND_SET_CONFIG, profileConfig) // 4. 禁用键盘输出插件(关键:阻止键盘模式生效) profileConfig.remove("PLUGIN_CONFIG") val keyboardConfig = Bundle() keyboardConfig.putString("PLUGIN_NAME", "KEYBOARD") keyboardConfig.putString("RESET_CONFIG", "true") val keyboardProps = Bundle() keyboardProps.putString("keyboard_output_enabled", "false") // 彻底关闭键盘输出 keyboardConfig.putBundle("PARAM_LIST", keyboardProps) profileConfig.putBundle("PLUGIN_CONFIG", keyboardConfig) dwInterface.sendCommandBundle(this, DWInterface.DATAWEDGE_SEND_SET_CONFIG, profileConfig) // 5. 配置并强制启用Intent输出(保留原有逻辑) profileConfig.remove("PLUGIN_CONFIG") val intentConfig = Bundle() intentConfig.putString("PLUGIN_NAME", "INTENT") intentConfig.putString("RESET_CONFIG", "true") val intentProps = Bundle() intentProps.putString("intent_output_enabled", "true") intentProps.putString("intent_action", PROFILE_INTENT_ACTION) intentProps.putString("intent_delivery", PROFILE_INTENT_BROADCAST) // 广播模式传递数据 intentConfig.putBundle("PARAM_LIST", intentProps) profileConfig.putBundle("PLUGIN_CONFIG", intentConfig) dwInterface.sendCommandBundle(this, DWInterface.DATAWEDGE_SEND_SET_CONFIG, profileConfig) }
2. 启动时自动创建配置
在configureFlutterEngine方法末尾添加调用,确保App启动时自动生成配置文件:
// 在configureFlutterEngine方法最后添加 createDataWedgeProfile("Flutter_Scan_Profile") // 自定义配置文件名,可按需修改
效果说明
- DataWedge会在你的App前台运行时自动切换到这个专属配置,无视设备全局的键盘模式设置。
- 扫描数据将直接通过Intent广播传递到Flutter端的
SCAN_CHANNEL,速度远快于键盘逐字符输入。 - 键盘输出被彻底禁用,不会出现扫描时自动弹出输入框的问题。
验证步骤
- 安装修改后的App到DT50设备。
- 打开设备的DataWedge应用,确认
Flutter_Scan_Profile已创建并关联你的App包名。 - 扫描条码,检查Flutter端是否通过
SCAN_CHANNEL接收到完整的扫描数据,同时键盘无输入动作。
内容的提问来源于stack exchange,提问作者Yuki
相关产品推荐
相关产品推荐

