Android ZBar QR Code Scanner - How to read every QR Code - android

I currently implemented ZBar QR Code Scanner Library into my own app. But, so far, I am just able to read a QR Code that leads to a website. What should I do if I want to scan a QR Code that leads you to dial a phone number or text messages? How do I make my app read any QR Code?

The content of the QR code should be irrelevant -- it's just text. It might happen to contain a URL, but that doesn't change the format of the QR code.
int result = imageScanner.scanImage(image);
// Nonzero means a result was found
if (result != 0) {
// Typical only one symbol unless multiple codes were found
// in the scanned image
for (Symbol symbol : imageScanner.getResults()) {
// .getData() gives the string content of the QR code
String qrCodeContent = symbol.getData();
}
}

Related

QR code not detecting in image BarcodeDetector

I have implemented QR codes detection from an image using BarcodeDetector
BarcodeDetector detector = new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(/*Barcode.DATA_MATRIX | Barcode.QR_CODE|*/Barcode.QR_CODE)
.build();
if (detector.isOperational()) {
Log.e("QR_READ", "Could not set up the detector!");
Frame frame = new Frame.Builder().setBitmap(pageBitmap).build();
QRCodeList = detector.detect(frame);
}
Here QRCodeList is empty but that image has QR code in it.
but some images are working with code but some are not detecting but those images I checked in online, those were working in that.
why that code not detecting QR code?
Maybe it's only a problem with those QRCodes which you are scanning. Try to use an online QRCode generator and check if it works for each QRCode you'll generate.
In addition , you could print the raw value returned from scanning.
This is Kotlin but you can convert it to Java . Something like that:
val rawScanValue: String = QRCodeList.valueAt(0).rawValue
// or toast or whatever
Log.d('RAWVALUE',rawScanValue)

Google Barcode API PDF417 not working

I've followed the directions in the Google codelab to get the Baracode API to detect and decode a standard QR code. I've done a simple integration to get the camera to provide the image and it works. Then I try a PDF417 bar code, and nothing.
Bitmap myBitmap = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.drawable.barcode);
BarcodeDetector detector =
new BarcodeDetector.Builder(getApplicationContext())
.setBarcodeFormats(Barcode.PDF417)
.build();
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Barcode> barcodes = detector.detect(frame);
Barcode thisCode = barcodes.valueAt(0);
barcodes is a zero length object and thisCode fails trying to get the value at position 0. I've tried feeding a PDF417 barcode I took a picture of as well as a barcode from an online generator.
Can someone help me?
Thanks in advance!!
A quick answer to your question, you either need to change the barcode flag to ALL_FORMATS (Barcode.ALL_FORMATS) or you should only provide the barcode. In other words, there should be no other visual information alongside the barcode (crop it). Otherwise, the API can't find the PDF-417 barcode.

How to parse contents in zxing barcode library in android

I am use zxing library for scanning data matrix barcode. I use zxing for barcode for scanning data matrix barcode type :
Barcode image :
Which has following detail :
LOC : VIP/ROYAL
item : 30000701293
UOI : Each
PAR : 35/50
It is working fine. I got properly output in contents.
Output :
1L+SK_CON_STR21LVIP/ROYAL.VIP/ROYAL....000000P+30000701293U+Each
So, how can i bifurgate all details ?
You parse it by writing Java code. Whatever this text is, its format is not a general standard, and so there is no library code that is already going to parse it.

Zxing detects on Android device but not on pc

I am using Zxing core.jar to scan bar codes and qr codes and it's working perfectly, but I want to make tests using Robolectric, to run automated tests without an emulator or device, that will take N number of images through zxing, so my problem is that zxing for some reason is not detecting any type of code format from the .jpg files, I'm not sure if there is a limit size on the image, or something else that I'm missing. The piece of code that does the detection is this, which works fine with frame previews converted to jpgs
BinaryBitmap bitmap = getBitmapFromImageData(input);
Collection<BarcodeFormat> decodeFormats = getDecodeFormats();
Map<DecodeHintType, Object> hints = getHints(decodeFormats);
MultiFormatReader multiFormatReader = getMultiFormatReader(hints);
Result rawResult;
try {
rawResult = multiFormatReader.decodeWithState(bitmap);
} catch (NotFoundException e) {
// not really an error, just QR code not found
Log.e(LOG_TAG, "Code Detection not found exception.");
return null;
}
Where the input contains the byte array in jpg format and is being converted by getBitmapFromImageData to Zxings internal formats. And like I said the library is working fine in the device, but I can't find any logical reason on why running this code from my pc won't work.
You're not showing any key code, like how you are reading your image. You should check whether it is being read correctly, being binarized correctly by your code, etc. Look at the unit tests in the project to see how to correctly read and process and image on the desktop. I don't know what your code may be doing in the "get" methods that is different.

ZXing: Scanning Barcode with UPC + 5 Supplemental

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.
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.
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
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);
}

Categories

Resources