Question

I want to perform some actions when my app scans a barcode. For that i need to know whenever my device scanner scans a barcode. Barcode contains a string which i want to use in my app. I searched a lot and tried to solve the problem using following code but i am not sure if i am on the right track because its not working:

In my onCreate method i am registering a broadcast receiver:

 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);

But i never receive anything. Any idea why or any other solution to solve this problem. Thanks in advance.

Was it helpful?

Solution

from the docs:

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.

that have nothing to do with barcode scanning. You have to see which library/method you're using to scan a barcode.

If you're using the XIng library I'm sure you have to call an activityForResult and then you just catch onActivityResult

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top