I am developing an Android application, and I need to encode and decode an array of bytes in the QRCode generated by the ZXing application. My problem is that my message decoded does not exactly match the generated byte array. I tried to create a QRCode based on an array of bytes containing incremental indices, i.e.
input = [0, 1, 2, ..., 124, 125, 126, 127, -128, -127,... -3, -2, -1, 0, 1, 2, ...]
And after encoding the message in QRCode and decoding it on the responder side, I get the following output of the byte array:
output = [0, 1, 2, ..., 124, 125, 126, 127, 63, 63,... 63, 63, 63, 0, 1, 2, ...]
All "negative" byte values ββare rotated to ASCII char 63: '?' question mark. I assume that something is wrong with the encoding of the encoding, but since I use ISO-8859-1, which everyone claims to be a solution to this kind of problem ( another topic, considering the same kind of question or here ), I do not see where is my mistake, or if I skip a step during instanciation encoding or decoding. Here is the code that I am executing to encode a given byte array:
String text = ""; byte[] res = new byte[272]; for (int i = 0; i < res.length; i++) { res[i] = (byte) (i%256); } try { text = new String(res, "ISO8859_1"); } catch (UnsupportedEncodingException e) {
And to decode the QRCode, I send the next Intent
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.qrcodeDecoding); Intent intent = new Intent(Intents.Scan.ACTION); intent.putExtra(Intents.Scan.MODE, Intents.Scan.QR_CODE_MODE); startActivityForResult(intent, 0); }
And wait for the result:
@Override protected void onActivityResult(int request, int result, Intent data) { if(request == 0) {
Could you tell me where are my mistakes, or where should I look?
Many thanks,
Franc