ZXing how to scan QR-Code AND 1D barcode?
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 开发者_Python百科the App able to scan both?? (1D and 2D barcode).
Thanks! Marco
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.
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);
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!
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");
精彩评论