Developing an Android application to scan Data Matrix codes using Google's MLKit, I'm unable to parse codes with data encoded in ISO-8859-1 encoding and containing Non-ASCII characters.
Here's an example: DataMatrix failing with ML Kit
val options = BarcodeScannerOptions.Builder()
.setBarcodeFormats(Barcode.FORMAT_DATA_MATRIX)
.build()
val scanner = BarcodeScanning.getClient(options)
scanner.process(image).addOnSuccessListener { barcodes ->
val barcode = barcodes.firstOrNull()
Log.i(TAG, barcode?.rawValue)
Log.i(TAG, String(barcode?.rawBytes!!, StandardCharsets.ISO_8859_1))
}
Both log statements return a string representing "Unknown encoding" (literally).
I'm using the latest version of MLKit's barcode-scanning library:
implementation 'com.google.mlkit:barcode-scanning:16.1.1
ZXing does the job, but it's having much more difficulties recognizing real life, not-so-perfect scans.
Any idea, any hint?
With the latest version of the ML Kit Barcode Scanning library 16.1.2, the rawBytes
method now returns the expected content of the QR code, also for non-unicode encodings.
implementation 'com.google.mlkit:barcode-scanning:16.1.2'