首页 > 解决方案 > 在 DataWedge 中以编程方式禁用扫描仪

问题描述

实际上我使用Output IntentfromDataWedge将解码后的数据发送到我的应用程序,所以在应用程序中记录了一个 BroadcastReceiver 来获取解码后的数据

private BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (Objects.equals(action, getResources().getString(R.string.activity_intent_filter_action))) {
            //  Received a barcode scan
            try {
                displayScanResult(intent);
            } catch (Exception e) {
                //  Catch if the UI does not exist when we receive the broadcast
            }
        }
    }
};

问题是是否可以在不使用 EMDK 的情况下以某种方式禁用扫描仪?如果以下条件为真,我将能够禁用扫描:

 if(Alerts.dialogError != null && Alerts.dialogError.isShowing()){
            // Here i should block the scanner
        }

标签: androiddatawedge

解决方案


是的,有两种方法,其中最简单的是:

Intent dwIntent = new Intent();
dwIntent.setAction("com.symbol.datawedge.api.ACTION");
//  Enable
dwIntent.putExtra("com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN", "ENABLE_PLUGIN");
//  or Disable
dwIntent.putExtra("com.symbol.datawedge.api.SCANNER_INPUT_PLUGIN", "DISABLE_PLUGIN");
sendBroadcast(dwIntent);

有关更多上下文,我刚刚在https://developer.zebra.com/blog/quickly-suspend-scanning-your-app-datawedge上写了一篇关于此的开发人员文章


推荐阅读