0

I have an android application where i have integrate the zxing barcode scanner. it working fine, but just one problem: i have another barcode scanner, so when my application going to call the barcode scanner, it always ask me to select the application.

I just want to force zxing to open with my application.

Any solution ?

manlio
  • 18,345
  • 14
  • 76
  • 126
Siraj Hussain
  • 874
  • 9
  • 25

2 Answers2

2

How do you call your Zxing Barcode Scanner? If you integrated it into your app, it shouldn't use intentPicker to let user choose one. You should be able to call it directly. But if not, you can do something similar to this:

Intent zxing = getZxingIntent(this);
zxing.putExtra( "com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE"); 
startActivityForResult(zxing, 0);

And the method to get ZxingIntent:

public static Intent getZxingIntent(Context context) {
    Intent zxingIntent = new Intent("com.google.zxing.client.android.SCAN");
    final PackageManager pm = context.getPackageManager();
    List<ResolveInfo> activityList = pm.queryIntentActivities(zxingIntent,
            0);
    for (int i = 0; i < activityList.size(); i++) {
        ResolveInfo app = activityList.get(i);
        if (app.activityInfo.name.contains("zxing")) {
            zxingIntent.setClassName(app.activityInfo.packageName,
                    app.activityInfo.name);
            return zxingIntent;
        }
    }
    return zxingIntent;
}

Edit: As refered this question when you send Zxing intent it searches for a barcode scanner, so if you have another barcode scanner it will create a picker. And if Zxing is not available on device you'll not be able to use it. So you should check it also. But anyway, the snipped that i provided above should work to find if Zxing is available on device. (However i didn't have chance to test it, so you may need to change a bit.)

Community
  • 1
  • 1
yahya
  • 4,810
  • 3
  • 41
  • 58
  • This is how i am calling Intent intent = new Intent( "com.google.zxing.client.android.SCAN"); intent.putExtra( "com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE"); startActivityForResult(intent, 0); – Siraj Hussain Jul 29 '13 at 06:56
  • I assume that your application is running and you are trying to start Zxing with code snipped that you gave? If so, it should work just fine. There should not be any intent picker, if you integrated correctly. – yahya Jul 30 '13 at 06:28
0

You may try this

Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.setPackage(getPackageName());
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
            startActivityForResult(intent, 0);
Karthik
  • 4,943
  • 19
  • 53
  • 86