0

I have developed 2 different applications and both have QR Code scanner. Now whenever I open any application and try to scan the code. It asks me to choose application to scan code. And displays both the applications. How can I force my application to not to ask and choose its own scanner?

Thanks in advance.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
hiren soni
  • 174
  • 2
  • 2
  • 17

1 Answers1

1

How can I force my application to not to ask and choose its own scanner?

Use an Intent that specifies the component (e.g., new Intent(this, MyScanner.class)).

However, please do not publish <intent-filter>s that you do not intend to honor. If you really are allowing both apps to scan barcodes, in theory the user should be able to choose between those apps, even from within the apps themselves. See: http://commonsware.com/blog/2012/07/09/dont-advertise-intent-filters-that-are-not-yours.html

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • HI CommonsWare, Your answers seems like the perfect answer but I am not able to understand it. I am very new to this platform. This is how my code looks like. Intent intent = new Intent("com.google.zxing.client.android.SCAN"); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 1); Can you please help modifying this code? – hiren soni Jul 16 '12 at 06:19
  • @hirensoni: If you are "very new to this platform", you should not be adding their code to your application and blindly adding their `` to your manifest, as you are doing the *exact* behavior that I point out in the blog entry that I link to above. If you are "very new to this platform", you should be integrating to the Barcode Scanner application, the way the ZXing team tells you to: http://code.google.com/p/zxing/wiki/ScanningViaIntent and is demonstrated here: https://github.com/commonsguy/cw-omnibus/tree/master/Camera/ZXing – CommonsWare Jul 16 '12 at 10:17
  • @hirensoni: If you insist upon doing what the ZXing team asks you not to do and adding their code directly to your project, you will need to modify their `CaptureActivity` to not use the `com.google.zxing.client.android.SCAN` action (known in Java code as `Intents.Scan.ACTION`), but rather some custom action of yours. Use that same action in your manifest in the `` for your copy of this activity, and use that action in your `Intent` when starting it. Use different actions for the two apps. – CommonsWare Jul 16 '12 at 10:21