I am working on QR And BarCode Scanning Android Application. For that I have used Zxing
Library. The Issue I am facing is, I am able to scan QR Code but as I scan any **barcode**
It is not giving the Result and Not able to scan the Bar Code.
I have gone through this stack overflow Answer but After Applying that the Issue of not been able to scan the barcode remain the same.
ZXing Android Studio barcode scanner not working with large barcodes and also the ZXing only recognizes QR-Code
before applying the above answers decode code looks like this
final class DecodeHandler extends Handler {
private final QrCodeScanningFragment mActivity;
private final QRCodeReader mQrCodeReader;
private final Map<DecodeHintType, Object> mHints;
private byte[] mRotatedData;
DecodeHandler(QrCodeScanningFragment activity) {
this.mActivity = activity;
mQrCodeReader = new QRCodeReader();
mHints = new Hashtable<>();
mHints.put(DecodeHintType.CHARACTER_SET, "utf-8");
mHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
mHints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
}
After applying the above Answers I have changed my Code to
DecodeHandler(QrCodeActivity activity) {
this.mActivity = activity;
mQrCodeReader = new QRCodeReader();
mHints = new Hashtable<>();
//mHints = new EnumMap<>(DecodeHintType.class);
mHints.put(DecodeHintType.CHARACTER_SET, "utf-8");
mHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
//mHints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
mHints.put(DecodeHintType.POSSIBLE_FORMATS, Arrays.asList(BarcodeFormat.AZTEC, BarcodeFormat.QR_CODE, BarcodeFormat.DATA_MATRIX,BarcodeFormat.UPC_A,
BarcodeFormat.CODABAR,BarcodeFormat.CODE_39,BarcodeFormat.CODE_93,BarcodeFormat.CODE_128,BarcodeFormat.EAN_8,BarcodeFormat.EAN_13,BarcodeFormat.MAXICODE,
BarcodeFormat.ITF,BarcodeFormat.PDF_417,BarcodeFormat.RSS_14,BarcodeFormat.RSS_EXPANDED,BarcodeFormat.UPC_EAN_EXTENSION
));
}
The Issue Remains the Same the app is Scanning QR But not Bar Code... For Now I have added all the Formats of QR Or Barcode added in my Decode Handler Code ... But Issue Of Not scanning barcode is still there.
This is QR REader Class, Here It is Showing barcode type as pureBarCode
public class QRCodeReader implements Reader {
private static final ResultPoint[] NO_POINTS = new ResultPoint[0];
private final Decoder decoder = new Decoder();
protected final Decoder getDecoder() {
return decoder;
}
/**
* Locates and decodes a QR code in an image.
*
* @return a String representing the content encoded by the QR code
* @throws NotFoundException if a QR code cannot be found
* @throws FormatException if a QR code cannot be decoded
* @throws ChecksumException if error correction fails
*/
@Override
public Result decode(BinaryBitmap image) throws NotFoundException, ChecksumException, FormatException {
return decode(image, null);
}
@Override
public final Result decode(BinaryBitmap image, Map<DecodeHintType,?> hints)
throws NotFoundException, ChecksumException, FormatException {
DecoderResult decoderResult;
ResultPoint[] points;
if (hints != null && hints.containsKey(DecodeHintType.PURE_BARCODE)) {
BitMatrix bits = extractPureBits(image.getBlackMatrix());
decoderResult = decoder.decode(bits, hints);
points = NO_POINTS;
} else {
DetectorResult detectorResult = new
Detector(image.getBlackMatrix()).detect(hints);
decoderResult = decoder.decode(detectorResult.getBits(), hints);
points = detectorResult.getPoints();
}
// If the code was mirrored: swap the bottom-left and the top-right points.
if (decoderResult.getOther() instanceof QRCodeDecoderMetaData) {
((QRCodeDecoderMetaData) decoderResult.getOther()).applyMirroredCorrection(points);
}
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
List<byte[]> byteSegments = decoderResult.getByteSegments();
if (byteSegments != null) {
result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments);
}
String ecLevel = decoderResult.getECLevel();
if (ecLevel != null) {
result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel);
}
if (decoderResult.hasStructuredAppend()) {
result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE,
decoderResult.getStructuredAppendSequenceNumber());
result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY,
decoderResult.getStructuredAppendParity());
}
return result;
}