ZXing:使用 UPC 扫描条形码 + 5 补充
我正在尝试使用 ZXing 库扫描如下所示的条形码。
(来源:minus.com)
// start scanning
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "ONE_D_MODE");
startActivityForResult(intent, REQUEST_CODE);
如果我替换“ONE_D_MODE”
与 “TWO_D_MODE”
时,应用程序可以成功检测这两个条形码;但 result
的值不会改变(仍然是 051488005995)。
// onActivityResult
if(requestCode == REQUEST_CODE && resultCode == RESULT_OK)
String result = intent.getStringExtra("SCAN_RESULT");
有没有办法同时获取条形码值 051488005995 和 50115?
任何其他获取条形码上方的 isbn (0142501158) 而不获取补充 +5 条形码 (50115) 的方法也很好。
谢谢。
I'm trying to scan barcode as shown below using the ZXing library.
(source: minus.com)
// start scanning
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "ONE_D_MODE");
startActivityForResult(intent, REQUEST_CODE);
If I replace "ONE_D_MODE"
with "TWO_D_MODE"
, the app can successfully detect both barcodes; but the value of result
won't change (still 051488005995).
// onActivityResult
if(requestCode == REQUEST_CODE && resultCode == RESULT_OK)
String result = intent.getStringExtra("SCAN_RESULT");
Is there any way to get both barcode value 051488005995 and 50115?
Any other way to obtain the isbn (0142501158) above the barcodes without getting the supplemental +5 barcode (50115) would also be great.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ONE_D_MODE
适合您。您可能确实想要PRODUCT_MODE
。不存在TWO_D_MODE
这样的东西。通过设置它只会扫描所有默认格式。它不扫描两个条形码。只需扫描产品代码即可。所以我不确定你所说的仅获取产品代码是什么意思:这就是你已经拥有的。我想你两者都想要。
MultipleBarcodeReader
不太适合这种情况,因为库的任何部分都不会自行扫描 UPC/EAN 补充。它仅作为 UPC 和 EAN 代码的扩展进行扫描。它已经在
UPCEANExtensionSupport
中扫描某些类型的扩展条形码。它不会返回原始值,而是尝试解析元数据并将其返回到结果元数据中。如果这就是你真正想要的,它已经做到了。否则就必须修改代码。如果它读取 UPC/EAN 代码但找不到扩展代码,则扫描不会失败,只会返回主代码。如果您希望它仅在找到两者时才返回,那么您必须再次更改核心库的副本。
ONE_D_MODE
will work for you. You probably really wantPRODUCT_MODE
. There is no such thing asTWO_D_MODE
. By setting this it just scans all default formats.It is not scanning both barcodes. It is just scanning the product code. So I'm not sure what you mean about getting just the product code: that's what you already have. I assume you want both.
MultipleBarcodeReader
is not quite for this situation as no part of the library scans for the UPC/EAN supplement by itself. It is scanned for as an extension to UPC and EAN codes only.It will already scan for some types of extension barcode in
UPCEANExtensionSupport
. It doesn't give you back the raw values but rather tries to parse out metadata and returns that in result metadata. If that's what you really want, it already does this. Otherwise you have to modify the code.If it reads the UPC/EAN code but can't find an extension code, it will not fail the scan, and will only return the primary code. If you want it to only return if both are found, again you'd have to change your copy of the core library.
仅供参考,您可以通过 Intent/zxing 扫描 UPC 12+5 代码。唯一的问题是你必须强制+5,所以你无法扫描正常的条形码。
从我与@srowen的帖子中: https://github.com/zxing/zxing/ issues/217#issuecomment-54818496
将提示作为 Intent 的额外内容传递给 IntentIntegrator=>initiateScan (稍后我必须创建一个重写方法来使其成为可选):
我确认它是从我的 Android logcat 中识别出来的:
在我的扫描结果中检索到扩展值:
现在我得到了一些 UPC 12+5 :)
FYI you can scan UPC 12+5 codes via Intent/zxing. The only catch is that you have to force the +5, so you can't scan normal barcodes.
From my thread with @srowen: https://github.com/zxing/zxing/issues/217#issuecomment-54818496
Passed the hint as an extra to the Intent, inside IntentIntegrator=>initiateScan (I'll have to make an overriden method to make this optional later):
I confirmed it was recognized from my Android logcat:
Retrieved extension values in my scan result:
Now I got some UPC 12+5 :)
据我所知,通过 Intent 使用 zxing 是不可能的。
但是,您可以直接将 ZXing 嵌入到代码中(通过将 ZXing 源添加到代码目录中)。然后您就可以使用
com.google.zxing.MultipleBarcodeReader
。函数decodeMultiple()
返回一个条形码数组,然后可以对其进行进一步处理。一个小例子:
As far as I know, this is not possible using zxing via an Intent.
However, you can embed ZXing in your code directly (by adding the ZXing source to your code directory). Then you are able to use the
com.google.zxing.MultipleBarcodeReader
. The functiondecodeMultiple()
returns an array of barcodes which then can be processed further.A small example: