Android Vision Barcode API - read custom QR code with binary data
Asked Answered
S

2

9

I use com.google.android.gms.vision.barcode.BarcodeDetector in order to read QR codes. The problem is these codes carry raw binary data; no phone numbers, no URLs, no geopoints... I cannot change these QR codes, because they are generated in a different application.

When I scan these QR codes using Android Barcode API, the resulting Barcode object doesn't allow me to access the raw data, although it must know it!

All I get is "Unknown encoding" message both in rawValue and displayValue properties.

Having a byte[] property instead of two String properties would make more sense, since QR codes can carry general data.

I don't see the point of hiding raw data byte array from developers. Could I somehow extend the BarcodeDetector class or the Barcode class to get what I need?

Edit:

This is an absolutely valid QR code, which cannot be read by Vision API, although it carries 1024 bytes of data:

enter image description here


QR Codes - raw binary data is related, but it doesn't solve my problem.

Shulem answered 24/11, 2016 at 14:52 Comment(6)
It's a very vague question... I too use the ...vision.barcode... api, in production code. Can you share an example QR?Dissect
@Dissect Sure, see my edit.Shulem
Sorry, I was hoping I could just output the (real) raw values from source but no luck there.. I guess there's null values or such in the data which makes the encoding fail. Seems extremely lame that the raw data aint available but.. Try filing an issue here. :(Dissect
Looks like ZXing is able to read the provided QR: zxing.org/w/… maybe you could use ZXing and drop the android api hereClyburn
I read raw data all the time with zxing.Otero
Also suggest you to use ZXing. I used most libraries which read QR code and i found ZXing as the fastest and most complete.Buckle
G
1

I think you need to write some of the implementation yourself. As I can clearly see in the API that the rawData is held by String which simply does not ensure the integrity of your binary data type.

I will write my own BarcodeDetector with my own BarCode object with byte[] as data type for rawData coming from QR-Code and override detect() method to assign the rawData to my BarCode implementation. As your case is very specific to the requirement you should not hesitate to write your own implementation. May be share it on github for others too.

Granvillegranvillebarker answered 19/1, 2017 at 15:29 Comment(0)
A
1

I've been reading QR-codes with binary content via this library module. The old ZXing did not provide the binary payload out of the box, however the new does provide the binary payload - but as far as I remember, only as part of a know format.

Anorthite answered 19/1, 2017 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.