Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In one of my apps I needed to encode and decode a bytes array in a QRCode generated with the ZXing app. As the byte array contained compressed text data I wanted to avoid base64 encoding. It is possible to do this but as I have so far not seen a complete set of code snippets I will post them here.</p> <p>Encoding:</p> <pre><code>public void showQRCode(Activity activity, byte[] data){ Intent intent = new Intent("com.google.zxing.client.android.ENCODE"); intent.putExtra("ENCODE_TYPE", "TEXT_TYPE"); intent.putExtra("ENCODE_SHOW_CONTENTS", false); intent.putExtra("ENCODE_DATA", new String(data, "ISO-8859-1")); activity.startActivity(intent); } </code></pre> <p>Start scanning:</p> <pre><code>public static void startQRCodeScan(Activity activity){ Intent intent = new Intent(com.google.zxing.client.android.SCAN); intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); intent.putExtra("CHARACTER_SET", "ISO-8859-1"); activity.startActivityForResult(intent, 0); } </code></pre> <p>Scan result handler:</p> <pre><code>public void onActivityResult(int requestCode, int resultCode, Intent intent) { byte[] result = intent.getStringExtra("SCAN_RESULT").getBytes("ISO-8859-1"); ... } </code></pre> <p>I think not setting CHARACTER_SET to ISO-8859-1 in the intent data for starting the scan is the point that made the code of the original question fail. It took me quite some time to dig this out as I have not seen this clearly posted anywhere and Latin 1 encoding is the standard encoding for QR code in Xzing. Especially tricky is the fact that the Xzing online decoder <a href="http://zxing.org/w/decode.jspx" rel="nofollow">http://zxing.org/w/decode.jspx</a> does not set CHARACTER_SET as well so that the generated QR code looks faulty when decoded on this site.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload