androidbarcodezxingaztec-barcode

Unable to encode aztec codes correctly


I am trying to create an aztec code with the payload below for android app with the help of zxing. However, after feeding this into the aztec generator, I am unable to read this payload after scanning the barcode. The reader linked to zxing decodes a completely different barcode payload.

Has anyone else seen this issue? Or am I generating the Aztec code incorrectly?

Thanks for the help

barcode_payload:

i¼\u0000\u0003\u0000\u0001\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000)X“}ôZv\u0002ô\u0000\u0000˜\u0012\u0012äNMGX†Ô\u0000\u0001Zv\u0002ô05\u0002\u0018T 64\u0011k\u0007m[\u000f瓉¿RÙƒ¨<úýá‹M\u0002\u0019\u0000 ɼÏØ\u0010Ë¢\u0003d·ã Í\u000bÚæ? Ÿ#+\u0017˜\u0000

Code:

public static Bitmap createAztec(String str, int mQrWidth, int mQrHeight, String timestampStr) { 
    String aztecStr; 
    if (!TextUtils.isEmpty(timestampStr)) { 
        aztecStr = str + "|" + timestampStr; 
    } else { 
        aztecStr = str; 
    } 
    AztecCode aztecCode = com.google.zxing.aztec.encoder.Encoder.encode(aztecStr.getBytes()); 
    BitMatrix matrix = aztecCode.getMatrix(); 
    if (matrix != null) { 
        int width = matrix.getWidth(); 
        int height = matrix.getHeight(); 
        int[] pixels = new int[width * height]; 
        for (int y = 0; y < height; y++) { 
            int offset = y * width; 
            for (int x = 0; x < width; x++) { 
                pixels[offset + x] = matrix.get(x, y) ? Color.BLACK : Color.WHITE; 
            } 
        } 
        Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
        bitmap.setPixels(pixels, 0, width, 0, 0, width, height); 
        return Bitmap.createScaledBitmap(bitmap, mQrWidth, mQrHeight, false); 
    } 
    return null; 
}

Solution

  • The solution was simple, instead of getting default UTF-8 charset, I had to use ISO-8859-1, ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1