注册/注销通知

DataWedge 7.4

REGISTER_FOR_NOTIFICATION

在 DataWedge 6.4 中引入。

使应用程序能够注册或注销,以接收与配置、扫描器和配置文件切换相关的状态更改通知。这些状态更改可能是由 DataWedge API 调用(如 IMPORT_CONFIGSWITCH_TO_PROFILESCANNER_INPUT_PLUGIN)或 DataWedge 配置文件更改(如配置文件自动导入)引起的。

函数原型

Bundle b = new Bundle(); b.putString("com.symbol.datawedge.api.APPLICATION_NAME","com.example.MyApp"); b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE","PROFILE_SWITCH"); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION", b); this.sendBroadcast(i);

参数

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

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

BUNDLE

  • APPLICATION_NAME - 要注册的应用程序的包名称
  • NOTIFICATION_TYPE - 支持的类型:
    • CONFIGURATION_UPDATE
    • PROFILE_SWITCH
    • SCANNER_STATUS

返回值

返回具有所请求 DataWedge 状态的捆绑包 NOTIFICATION_TYPE

EXTRA NAME:"com.symbol.datawedge.api.NOTIFICATION"

BUNDLE

  • CONFIGURATION_UPDATE [字符串]:

    • "PROFILE_IMPORTED" "FULL_DB_IMPORTED"
    • "PROFILE_NAME": “<应用程序包名称>”
  • PROFILE_SWITCH:

    • "PROFILE_IMPORTED" "FULL_DB_IMPORTED"
    • "PROFILE_NAME": “<现在正在使用的配置文件名称>”
  • SCANNER_STATUS:

    • WAITING - 扫描器已启用并准备使用物理触发器或 SOFT_SCAN_TRIGGER Intent 进行扫描。

    • SCANNING - 扫描器已发射扫描光束,并且扫描正在进行。此事件不会阻止应用程序在必要时禁用其他控件。

    • CONNECTED - 蓝牙扫描器已与设备连接,并且现在可以通过应用程序启用(或禁用)。在当前活动的配置文件中,扫描器选项应设置为“自动”。

    • DISCONNECTED - 蓝牙扫描器已从设备断开。在此状态下发送启用或禁用扫描器的 Intent 将启用/禁用当前默认扫描器。

    • IDLE - 扫描器处于以下状态之一:已启用,但尚未处于等待状态;通过 Intent(例如 SUSPEND_PLUGIN)处于挂起状态;或因硬件触发器而处于已禁用状态。

    • DISABLED - 扫描器处于禁用状态。当手动禁用活动配置文件或使用 Intent(例如 DISABLE_PLUGIN)禁用扫描器时,扫描器插件会广播此信息。

仅在启用活动配置文件中的扫描器时,才发送扫描器状态通知

注意:(当前处于活动的配置文件的)PROFILE_NAME使用 SCANNER_STATUS 返回,允许开发人员仅过滤所需配置文件的扫描器事件。

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

$ adb logcat -s DWAPI

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

示例代码

// TO REGISTER AN APP TO RECIEVE NOTIFICATIONS // Register for notifications - PROFILE_SWITCH Bundle b = new Bundle(); b.putString("com.symbol.datawedge.api.APPLICATION_NAME","com.example.intenttest"); b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE","PROFILE_SWITCH"); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION", b); // (1) this.sendBroadcast(i); // To unregister, change only the iPutExtra command Bundle b = new Bundle(); b.putString("com.symbol.datawedge.api.APPLICATION_NAME","com.example.intenttest"); b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE","PROFILE_SWITCH"); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.UNREGISTER_FOR_NOTIFICATION", b); this.sendBroadcast(i); // Register for notifications - SCANNER_STATUS Bundle b = new Bundle(); b.putString("com.symbol.datawedge.api.APPLICATION_NAME","com.example.intenttest"); b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE", "SCANNER_STATUS"); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.REGISTER_FOR_NOTIFICATION", b);//(1) this.sendBroadcast(i); // To unregister, change only the iPutExtra command Bundle b = new Bundle(); b.putString("com.symbol.datawedge.api.APPLICATION_NAME","com.example.intenttest"); b.putString("com.symbol.datawedge.api.NOTIFICATION_TYPE", "SCANNER_STATUS"); Intent i = new Intent(); i.setAction("com.symbol.datawedge.api.ACTION"); i.putExtra("com.symbol.datawedge.api.UNREGISTER_FOR_NOTIFICATION", b); this.sendBroadcast(i); // TO RECIEVE NOTIFICATIONS public static final String NOTIFICATION_ACTION = "com.symbol.datawedge.api.NOTIFICATION_ACTION"; public static final String NOTIFICATION_TYPE_SCANNER_STATUS = "SCANNER_STATUS"; public static final String NOTIFICATION_TYPE_PROFILE_SWITCH = "PROFILE_SWITCH"; public static final String NOTIFICATION_TYPE_CONFIGURATION_UPDATE = "CONFIGURATION_UPDATE"; private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); Log.d(TAG, "#DataWedge-APP# Action: " + action); if(action.equals(NOTIFICATION_ACTION)){ if(intent.hasExtra("com.symbol.datawedge.api.NOTIFICATION")) { Bundle b = intent.getBundleExtra("com.symbol.datawedge.api.NOTIFICATION"); String NOTIFICATION_TYPE = b.getString("NOTIFICATION_TYPE"); if(NOTIFICATION_TYPE!= null) { switch (NOTIFICATION_TYPE) { case NOTIFICATION_TYPE_SCANNER_STATUS: Log.d(TAG, "SCANNER_STATUS: status: " + b.getString("STATUS") + ", profileName: " + b.getString("PROFILE_NAME")); break; case NOTIFICATION_TYPE_PROFILE_SWITCH: Log.d(TAG, "PROFILE_SWITCH: profileName: " + b.getString("PROFILE_NAME") + ", profileEnabled: " + b.getBoolean("PROFILE_ENABLED")); break; case NOTIFICATION_TYPE_CONFIGURATION_UPDATE: break; } } } } } }; void registerReceivers() { //to register the broadcast receiver IntentFilter filter = new IntentFilter(); filter.addAction(NOTIFICATION_ACTION); registerReceiver(broadcastReceiver, filter);//Android method } void unRegisterReceivers() { //to unregister the broadcast receiver unregisterReceiver(broadcastReceiver); //Android method }

注释

(无)


另请参阅

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

LaunchPad | Zebra 开发人员社区

Intent | Android 开发人员

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

Android Intent | 教程