Saify
Saify

Reputation: 491

Vision api not detecting QR code on some devices

I am using Vision api for detecting QR codes. It works well on a samsung device but not on LG device. Both devices are running on version 6.0.1 and there's no error as well. Any advice?

Upvotes: 1

Views: 1229

Answers (2)

Erselan Khan
Erselan Khan

Reputation: 845

I faced this same issue that QR not detected on Redmi and Infinix devices, here is my solution:

Zxing Library Version

implementation 'com.google.zxing:core:3.4.0'

Just pass your Bitmap in this function and this will return the string value:

public static String getQRDataFromBitmap(Bitmap bitmap) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
    int[] intArray = new int[bitmap.getWidth() * bitmap.getHeight()];
    bitmap.getPixels(intArray, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
    LuminanceSource source = new RGBLuminanceSource(bitmap.getWidth(), bitmap.getHeight(), intArray);
    Reader reader = new MultiFormatReader();
    try {
        Result result = reader.decode(new BinaryBitmap(new HybridBinarizer(source)));
        return result.getText();
    } catch (NotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (ChecksumException e) {
        e.printStackTrace();
        return null;
    } catch (FormatException e) {
        e.printStackTrace();
        return null;
    }
}

Upvotes: 0

Attaullah
Attaullah

Reputation: 4021

Here some sample of Zxing-Library and Vision API hope it will help you.

The sample projects base on Zxing-Library

Zxing Code Sample1 or

Zxing Code Sample2

While Vision API for QR Bar Code try this

Vision API Code Sample1 or enter image description here

Vision API Code Sample2 or

Vision API Code Sample3

Upvotes: 1

Related Questions