Android QR Code Scanner Not Recognizing Text or Wifi

Viewed 102

I am building an Android QR scanner app, and I used a code shared by "Android Coding Time" YouTube channel. The code is specified to read text, wifi and url.

The app ended up reading the URL but it's not recognizing text or Wifi. The code is attached, any thoughts?

// I even throw "Barcode.FORMAT_ALL_FORMATS" hoping it would work, but it didn't!

private void scanbarcode(ImageProxy image) {

        @SuppressLint("UnsafeOptInUsageError") Image image1 = image.getImage();
        assert image1 != null;
        InputImage inputImage = InputImage.fromMediaImage(image1, image.getImageInfo().getRotationDegrees());
        BarcodeScannerOptions options =
                new BarcodeScannerOptions.Builder()
                        .setBarcodeFormats(
                                Barcode.FORMAT_ALL_FORMATS,
                                Barcode.FORMAT_QR_CODE,
                                Barcode.FORMAT_AZTEC)
                        .build();

// the switch block

int valueType = barcode.getValueType();
            switch (valueType) {
                case Barcode.TYPE_WIFI:
                    String ssid = barcode.getWifi().getSsid();
                    String password = barcode.getWifi().getPassword();
                    int type = barcode.getWifi().getEncryptionType();
                    break;
                case Barcode.TYPE_URL:
                    if (!bd.isAdded()) {
                        bd.show(fragmentManager, "");
                    }
                    bd.fetchurl(barcode.getUrl().getUrl());

                    String title = barcode.getUrl().getTitle();
                    String url = barcode.getUrl().getUrl();
                    break;

                case Barcode.TYPE_TEXT:
                    byte[] codeText = barcode.getRawValue().getBytes(StandardCharsets.UTF_8);
                    break;
1 Answers

To share with you guys, I got the code running by changing the .setBarcodeFormats to:

new BarcodeScannerOptions.Builder()
                    .setBarcodeFormats(
                            Barcode.FORMAT_QR_CODE)
Related