Zebra 扫描仪服务

如何解决Zebra 扫描仪服务

我正在使用 Zebra TC26 扫描仪,想创建一个可以触发扫描和读取条形码的后台 Java 服务。

我有一个没有活动且只有一项服务的应用程序(此服务是我的应用程序和 zebra 扫描仪 api 之间的中间人)。我实现了一个 broadcastReceiver,它似乎适用于操作结果,例如软扫描触发结果和配置结果。发送 SOFT_SCAN_TRIGGER 操作将开始扫描,但我从未收到带有条形码的结果。只有命令结果。

当我在带有活动的单独应用程序中运行相同的代码时,它会起作用,并且我会重新获得扫描的代码。我需要怎么做才能通过这个没有活动的服务接收扫描的代码

public class MyService extends Service {

    private broadcastReceiver broadcastReceiver = new broadcastReceiver() {
        @Override
        public void onReceive(Context context,Intent intent) {
            String decodedSource = intent.getStringExtra(SOURCE);
            String decodedData = intent.getStringExtra(DATA_STRING);
            // ...
        }
    };

    // ...

    private void startListening() {
        IntentFilter filter = new IntentFilter();
        filter.addCategory(Intent.CATEGORY_DEFAULT);
        filter.addAction(MY_ACTION);
        registerReceiver(broadcastReceiver,filter);
    }

    public void triggerScan() {
        Intent i = new Intent();
        i.setAction(ACTION);
        i.putExtra(SWITCH_PROFILE,MY_PROFILE);
        i.putExtra("SEND_RESULT","true");
        i.putExtra(SOFT_SCAN_TRIGGER,"START_SCANNING");
        this.sendbroadcast(i);
    }

    // ...


    private void initConfiguration(){
        Bundle bundleMain = new Bundle();
        // profile name and state
        bundleMain.putString("PROFILE_NAME",MY_PROFILE);
        bundleMain.putString("PROFILE_ENABLED","true");
        bundleMain.putString("CONfig_MODE","UPDATE");


        // Associate profile with this app
        Bundle appConfig = new Bundle();
        appConfig.putString("PACKAGE_NAME",getPackageName());
        appConfig.putStringArray("ACTIVITY_LIST",new String[]{"*"});
        bundleMain.putParcelableArray("APP_LIST",new Bundle[]{appConfig});

        // Configure intent output for captured data to be sent to this app
        Bundle bundleIntentOutConfig = new Bundle();
        bundleIntentOutConfig.putString("PLUGIN_NAME","INTENT");
        bundleIntentOutConfig.putString("RESET_CONfig","false");

        // Param list properties
        Bundle bundleIntentParams = new Bundle();
        bundleIntentParams.putString("intent_output_enabled","true");
        bundleIntentParams.putString("intent_action",MY_ACTION);
        bundleIntentParams.putString("intent_category",Intent.CATEGORY_DEFAULT);
        bundleIntentParams.putString("intent_delivery","2");   //0 - activity,1 - service,2 - broadcast
        bundleIntentOutConfig.putBundle("ParaM_LIST",bundleIntentParams);

        ArrayList<Bundle> bundlePluginConfig = new ArrayList<>();
        bundlePluginConfig.add(bundleIntentOutConfig);

        bundleMain.putParcelableArrayList("PLUGIN_CONfig",bundlePluginConfig);

        Intent bundleSetConfig = new Intent();
        bundleSetConfig.setAction(ACTION);
        bundleSetConfig.putExtra(SET_CONfig,bundleMain);
        bundleSetConfig.putExtra("SEND_RESULT","COMPLETE_RESULT"); //Supported values: NONE,LAST_RESULT,COMPLETE_RESULT
        bundleSetConfig.putExtra("COMMAND_IDENTIFIER","INTENT_API");
    }
}

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <service
        android:name=".MyService"
        android:enabled="true"
        android:exported="true">
    </service>
</application>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?