简体   繁体   English

ZXing如何扫描QR码和1D条码?

[英]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 : 我刚刚在我的应用程序中导入了ZXing库,我知道如何设置putExtra函数来扫描QR-Code条码

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?? 但是如何让App能够同时扫描? (1D and 2D barcode). (1D和2D条形码)。

Thanks! 谢谢! Marco 马尔科

If you just want to scan both (and not exclusively these two): 如果您只想扫描两者(而不仅仅是这两个):

Don't add the SCAN_MODE extra to the intent. 不要将SCAN_MODE额外添加到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);

you should use "SCAN_MODE" instead of "QR_CODE_MODE": 你应该使用“SCAN_MODE”而不是“QR_CODE_MODE”:

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

should be 应该

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

I recommend using IntentIntegrator it is a class the Zxing project has that I am using with one of my apps. 我建议使用IntentIntegrator它是Zxing项目的一个类,我正在使用我的一个应用程序。 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. initiateScan方法是您想要查看的地方。 Enjoy! 请享用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM