zxing-android-embedded
zxing-android-embedded copied to clipboard
Binary data in QR Code
Description of the problem:
Hello, I have encrypted string ³.ôÜ ^ZÌP>¼êñe¶¼ÌØ#m;¡Â& èB]ÀÆS5 (Using encoded format "ISO-8859-1")
Byte array used to create above encrypted string is 0 = 1 1 = 2 2 = 3 3 = -104 4 = 76 5 = 107 6 = 118 7 = -104 8 = 76 9 = 107 10 = 118 11 = 3 12 = 50 13 = 55 14 = -1 15 = -1 16 = -1 17 = -1 18 = -1 19 = -1 20 = -1 21 = -1 22 = 50 23 = 55 24 = 2 25 = 2 26 = 2 27 = 49 28 = 49 29 = 50 30 = 50 31 = 51
I am able to generate QR code from the above encrypted string. When I scan the encrypted string from the qr code by using following code ,String coming from IntentIntegrator is different
String received from Scanner �.��� ^Z�P�>���e����#m;��& �B]���S5�
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); if (result != null) { if (result.getContents() == null) { Toast.makeText(this, getResources().getString(R.string.qr_scan_result_notfound), Toast.LENGTH_LONG).show(); } else { try { String result_data= result.getContents(); } Which library version are you using? 'com.journeyapps:zxing-android-embedded:3.4.0' E.g. 3.2.0.
**Which phone/tablet are you using, and which Android version does it run? (e.g. Samsung Galaxy S5, Android 5.0) Moto G3 **
Does the same happen on other devices or an emulator?
Can you reproduce the issue in the sample project included with the library? If not, can you provide your own sample project or sample code that produces this error?
In the case of an error do you have a stack trace or adb logs?
Hello, Can anybody share input for the same, please?
There are two issues here:
- By converting the binary data to a string, you are most likely already losing some info (e.g. the -1s in the data).
- The string encoding is not well defined for QR codes, so some guesswork is done when decoding, and it most likely uses UTF8.
For this use case, you should just base64-encode the data, which would avoid both issues.
Hello Kistner, We tried base 64 encoding on top of ISO-8859-1 and were able to get the appropriate scan result. Now the issue is, the QR that was getting generated earlier was version 3 and the one getting generated after Base 64 is version 4. We need version 3 for our project. Can you please help us achieve the same?
Thanks and Regards,
I did a quick check and it may be possible to encode binary data directly into the QR Code (byte[], not String), and bypass the String encoding / decoding completely, but:
- This will require modifying internals in the core zxing code.
- It may or may not be following the QR code specs.
- It will most likely not be compatible with other barcode scanners.
Instead of base64, there are some slightly more compact encodings available, such as Ascii85, which will perhaps be sufficient for your use case. If not, you'll have to get by with less data, or change your requirements to allow version 4 barcodes.
for encoding byte array in QR code i used "io.nayuki:qrcodegen" + "com.caverock:androidsvg-aar"libraries. "nayuki" converts byte array to SVG string, "androidsvg" converts SVG string to bitmap, then bitmap i set to imageview. using the zxing it did not work.