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

前端 未结 2 1385
情深已故
情深已故 2021-01-15 05:03

I\'m working with the zxing QR code APIs, and I\'m trying to extract binary data from a QR code on an android device. However, on android, Result.getResultMetadata() isn\'t

相关标签:
2条回答
  • 2021-01-15 05:25

    Why not start with the javadoc?

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

    0 讨论(0)
  • 2021-01-15 05:40

    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.

    0 讨论(0)
提交回复
热议问题