Flutter应用中DataWedge配置文件创建后配置不生效的解决
Flutter集成Zebra DataWedge配置无效问题
我正在开发一款集成Zebra条码扫描器的Flutter应用,需要在初始化阶段创建并配置DataWedge配置文件。目前代码能成功创建指定名称的配置文件,但后续的应用关联、条码插件配置、Intent插件配置均未生效,尝试多种方法仍无法解决。
问题代码
// ignore_for_file: avoid_print import 'package:android_intent_plus/android_intent.dart'; import 'dart:convert'; void configureDataWedgeProfile() async { const profileName = "app_coletor"; const packageName = "com.kugel.app_coletor"; const intentAction = "com.kugel.app_coletor.ACTION"; try { print("Criando perfil do DataWedge..."); await AndroidIntent( action: "com.symbol.datawedge.api.ACTION", arguments: {"com.symbol.datawedge.api.CREATE_PROFILE": profileName}, ).sendBroadcast(); await Future.delayed(const Duration(seconds: 2)); print("Associando aplicativo ao perfil..."); await AndroidIntent( action: "com.symbol.datawedge.api.ACTION", arguments: { "com.symbol.datawedge.api.SET_CONFIG": jsonEncode({ "PROFILE_NAME": profileName, "PROFILE_ENABLED": "true", "CONFIG_MODE": "UPDATE", "APP_LIST": [ { "PACKAGE_NAME": packageName, "ACTIVITY_LIST": ["*"] } ] }) }, ).sendBroadcast(); await Future.delayed(const Duration(seconds: 2)); print("Configurando o plugin de código de barras..."); await AndroidIntent( action: "com.symbol.datawedge.api.ACTION", arguments: { "com.symbol.datawedge.api.SET_CONFIG": jsonEncode({ "PROFILE_NAME": profileName, "CONFIG_MODE": "UPDATE", "PLUGIN_CONFIG": { "PLUGIN_NAME": "BARCODE", "RESET_CONFIG": "true", "PARAM_LIST": { "scanner_selection": "auto", "decode_audio_feedback_uri": "file:///system/media/audio/ui/VideoRecord.ogg" } } }) }, ).sendBroadcast(); await Future.delayed(const Duration(seconds: 2)); print("Configurando o plugin de intent..."); await AndroidIntent( action: "com.symbol.datawedge.api.ACTION", arguments: { "com.symbol.datawedge.api.SET_CONFIG": jsonEncode({ "PROFILE_NAME": profileName, "CONFIG_MODE": "UPDATE", "PLUGIN_CONFIG": { "PLUGIN_NAME": "INTENT", "RESET_CONFIG": "true", "PARAM_LIST": { "intent_output_enabled": "true", "intent_action": intentAction, "intent_delivery": "2" } } }) }, ).sendBroadcast(); print("Perfil do DataWedge configurado e app vinculado!"); } catch (e) { print("Erro ao configurar o DataWedge: $e"); } }
问题排查与修复方案
核心问题出在参数传递格式错误,以及部分参数类型不匹配:
- 无需手动JSON编码:
AndroidIntent的arguments会自动处理参数序列化,你手动用jsonEncode把配置转成字符串后,DataWedge无法解析嵌套的配置结构。 - 布尔值参数需用原生类型:
PROFILE_ENABLED、RESET_CONFIG、intent_output_enabled这类参数需要传递布尔值true,而非字符串"true"。
修复后的代码
// ignore_for_file: avoid_print import 'package:android_intent_plus/android_intent.dart'; void configureDataWedgeProfile() async { const profileName = "app_coletor"; const packageName = "com.kugel.app_coletor"; const intentAction = "com.kugel.app_coletor.ACTION"; try { print("Criando perfil do DataWedge..."); await AndroidIntent( action: "com.symbol.datawedge.api.ACTION", arguments: {"com.symbol.datawedge.api.CREATE_PROFILE": profileName}, ).sendBroadcast(); await Future.delayed(const Duration(seconds: 1)); print("Associando aplicativo ao perfil..."); await AndroidIntent( action: "com.symbol.datawedge.api.ACTION", arguments: { "com.symbol.datawedge.api.SET_CONFIG": { "PROFILE_NAME": profileName, "PROFILE_ENABLED": true, "CONFIG_MODE": "UPDATE", "APP_LIST": [ { "PACKAGE_NAME": packageName, "ACTIVITY_LIST": ["*"] } ] } }, ).sendBroadcast(); await Future.delayed(const Duration(seconds: 1)); print("Configurando o plugin de código de barras..."); await AndroidIntent( action: "com.symbol.datawedge.api.ACTION", arguments: { "com.symbol.datawedge.api.SET_CONFIG": { "PROFILE_NAME": profileName, "CONFIG_MODE": "UPDATE", "PLUGIN_CONFIG": { "PLUGIN_NAME": "BARCODE", "RESET_CONFIG": true, "PARAM_LIST": { "scanner_selection": "auto", "decode_audio_feedback_uri": "file:///system/media/audio/ui/VideoRecord.ogg" } } } }, ).sendBroadcast(); await Future.delayed(const Duration(seconds: 1)); print("Configurando o plugin de intent..."); await AndroidIntent( action: "com.symbol.datawedge.api.ACTION", arguments: { "com.symbol.datawedge.api.SET_CONFIG": { "PROFILE_NAME": profileName, "CONFIG_MODE": "UPDATE", "PLUGIN_CONFIG": { "PLUGIN_NAME": "INTENT", "RESET_CONFIG": true, "PARAM_LIST": { "intent_output_enabled": true, "intent_action": intentAction, "intent_delivery": "2" } } } }, ).sendBroadcast(); print("Perfil do DataWedge configurado e app vinculado!"); } catch (e) { print("Erro ao configurar o DataWedge: $e"); } }
额外注意事项
- 确保设备上的DataWedge版本支持所用API,部分旧版本对参数格式要求更严格。
- 在AndroidManifest.xml中添加必要权限:
<uses-permission android:name="android.permission.BROADCAST_STICKY" /> - 测试时可打开DataWedge应用手动检查配置是否生效,快速定位问题。
内容的提问来源于stack exchange,提问作者Otávio Luiz Nandi
相关产品推荐
相关产品推荐

