ZXing Result.getRawBytes(), what exactly is it?

老子叫甜甜 提交于 2019-12-06 07:24:53

So what i think you want is the raw, decoded data in a byte array. The intent source that zxing gives you is missing the metadata, but it's still being sent to the intent filter.

In parseActivityResult inside of IntentIntegrator.java, you can add:

byte[] dataBytes = intent.getByteArrayExtra("SCAN_RESULT_BYTE_SEGMENTS_0");
return new IntentResult(contents,
                        formatName,
                        rawBytes,
                        orientation,
                        errorCorrectionLevel,
                        dataBytes);

I modified the IntentResult class to be able to take this extra piece:

private final byte[] dataBytes;

IntentResult() {
    this(null, null, null, null, null, null);
}

IntentResult(String contents,
           String formatName,
           byte[] rawBytes,
           Integer orientation,
           String errorCorrectionLevel,
           byte[] dataBytes) {
    this.contents = contents;
    this.formatName = formatName;
    this.rawBytes = rawBytes;
    this.orientation = orientation;
    this.errorCorrectionLevel = errorCorrectionLevel;
    this.dataBytes = dataBytes;
}


/**
* @return raw content of barcode in bytes
*/

public byte [] getDataBytes() {
  return dataBytes;
}

This byte array stores the first array of the metadata, AKA the raw contents of your data in bytes.

Why not start with the javadoc?

It is the raw codewords in the QR code. It is not the individual parsed byte segments.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!