java - 如何知道扫描仪是否已经扫描完android中的条码?

标签 java android android-intent broadcastreceiver intentfilter

我想在我的应用扫描条形码时执行一些操作。为此,我需要知道我的设备扫描仪何时扫描条形码。条形码包含一个我想在我的应用程序中使用的字符串。我搜索了很多并尝试使用以下代码解决问题,但我不确定我是否走在正确的轨道上,因为它不起作用:

在我的 onCreate 方法中,我正在注册一个广播接收器:

 IntentFilter filter = new IntentFilter();
 filter.addAction(Intent.ACTION_MEDIA_SCANNER_FINISHED);
 filter.addDataScheme("file");

 receiver = new BroadcastReceiver() {
 @Override
 public void onReceive(Context context, Intent intent) {
      String action = intent.getAction();
      System.out.println("intent action:"+action);
      System.out.println("intent recieved");
     }
 };

 getActivity().registerReceiver(receiver, filter);

但我从来没有收到过任何东西。知道为什么或任何其他解决方案来解决这个问题。提前致谢。

最佳答案

来自文档:

Intent.ACTION_MEDIA_SCANNER_FINISHED

Broadcast Action: The media scanner has finished scanning a directory. The path to the scanned directory is contained in the Intent.mData field.

与条形码扫描无关。您必须查看正在使用哪个库/方法来扫描条形码。

如果您使用 XIng 库,我确定您必须调用 ActivityForResult,然后您只需捕获 onActivityResult

关于java - 如何知道扫描仪是否已经扫描完android中的条码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19703873/

相关文章:

java - 将 Arraylist 附加到 TextView

android - 使用深层链接从另一个启动应用程序

android - Activity 未找到异常 : Unable to find explicit activity class

java - 在文本框中设置日期?

java - 如何在抛出异常后循环程序

java - 将纬度和经度值设置到文本框

Android 在 onPause 中保存 Activity 动态创建的布局

java - Android:使用AudioTrack和Socket手动高效地流音频

android - 如何在android中重命名文件?

android - 无法解析配置 ':_armv7DebugCompile' 的所有依赖项