ZXing Result.getRawBytes(),究竟是什么?

Jai*_*ung 2 java android zxing

我正在使用zxing QR代码API,我正在尝试从Android设备上的QR代码中提取二进制数据.但是,在android上,Result.getResultMetadata()没有通过Intent传递给我,所以我尝试使用Result.getRawBytes()来检索我的字节数组.但是,getRawBytes()似乎没有返回相同的东西.

究竟是什么Result.getRawBytes()并且有谁知道如何正确地从zxing QR码中提取字节数组?

谢谢

yhy*_*nus 5

所以我认为你想要的是字节数组中的原始解码数据.zxing给你的意图源是缺少元数据,但它仍然被发送到intent过滤器.

在IntentIntegrator.java中的parseActivityResult中,您可以添加:

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

我修改了IntentResult类以便能够获取这个额外的部分:

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;
}
Run Code Online (Sandbox Code Playgroud)

此字节数组存储元数据的第一个数组,AKA是数据的原始内容(以字节为单位).