Reputation: 309
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.
Upvotes: 5
Views: 8306
Reputation: 129
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):
// Force 5 digit extension
intentScan.putExtra("ALLOWED_EAN_EXTENSIONS", new int[] {5});
I confirmed it was recognized from my Android logcat:
DecodeHintManager﹕ Hints from the Intent: {ALLOWED_EAN_EXTENSIONS=[I@42a38540}
Retrieved extension values in my scan result:
String extension = intent.getStringExtra("SCAN_RESULT_UPC_EAN_EXTENSION");
Now I got some UPC 12+5 :)
Content:079808007955, Format:UPC_A, Extension: 74700
Upvotes: 1
Reputation: 66876
ONE_D_MODE
will work for you. You probably really want PRODUCT_MODE
. There is no such thing as TWO_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.
Upvotes: 3
Reputation: 1753
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 function decodeMultiple()
returns an array of barcodes which then can be processed further.
A small example:
// data: YUV camera preview; width/height: preview size
Result[] decode(byte[] data, int width, int height) {
PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
MultipleBarcodeReader reader = new MultipleBarcodeReader(new MultiFormatOneDReader(null));
return reader.decodeMultiple(bitmap);
}
Upvotes: 0