20

I just imported the ZXing library in my app, I know how to set up the putExtra function to scan QR-Code barcode:

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

and if I like to scan a 1D barcode:

INTENT = new Intent("com.google.zxing.client.android.SCAN");
INTENT.putExtra("SCAN_MODE", "PRODUCT_MODE");
startActivityForResult(INTENT, 0);

but how do I make the App able to scan both?? (1D and 2D barcode).

Thanks! Marco

MataMix
  • 3,276
  • 10
  • 39
  • 58

4 Answers4

28

If you just want to scan both (and not exclusively these two):

Don't add the SCAN_MODE extra to the intent. Thats optional to limit the type of barcode to a certain type. Not specifying it will scan all possible types.

7

Just go through these line of code. It is working for me perfectly as you want.

 Intent intent = new Intent("com.google.zxing.client.android.SCAN");
              intent.setPackage("com.google.zxing.client.android"); 
              //intent.putExtra("SCAN_MODE", "PRODUCT_MODE");
              intent.putExtra("SCAN_FORMATS", "CODE_39,CODE_93,CODE_128,DATA_MATRIX,ITF,CODABAR,EAN_13,EAN_8,UPC_A,QR_CODE");
              startActivityForResult(intent, 0);
DJhon
  • 1,548
  • 3
  • 22
  • 39
2

you should use "SCAN_MODE" instead of "QR_CODE_MODE":

INTENT.putExtra("SCAN_MODE", "QR_CODE_MODE");

should be

INTENT.putExtra("SCAN_MODE", "SCAN_MODE");
kfsone
  • 23,617
  • 2
  • 42
  • 74
2

I recommend using IntentIntegrator it is a class the Zxing project has that I am using with one of my apps. I have provided a link to the file. It encapsulates the scan code and is great for simple scanning function. initiateScan method is where you want to look. Enjoy!

onof
  • 17,167
  • 7
  • 49
  • 85
markS
  • 580
  • 5
  • 14