4

I am trying to use Google's new code scanner for scanning QR codes in an Android app, when a button is clicked, but I get a black screen.

Here is my code:

binding.scanQR.setOnClickListener {
    val options = GmsBarcodeScannerOptions.Builder()
        .setBarcodeFormats(Barcode.FORMAT_QR_CODE, Barcode.FORMAT_AZTEC)
        .build()

    GmsBarcodeScanning.getClient(this, options).startScan().addOnSuccessListener {
        model.onScanAddress(it.rawValue)?.let { address ->
            binding.address.setText(address)
        }
    }.addOnFailureListener {
        Timber.e(it)
    }
}

And here is what happens when I click the button: enter image description here


There are no error/warn logs, so I'm a bit stuck here. Any ideas?

tzegian
  • 394
  • 3
  • 13
  • Tried to manage camera permission before launching it ? – jayesh gurudayalani May 30 '23 at 12:10
  • Hey, thanks for replying! I am having the exact same issue as @tzegian. But the first line in the documentation is "The Google code scanner API provides a complete solution for scanning codes without requiring your app to request camera permission": https://developers.google.com/ml-kit/vision/barcode-scanning/code-scanner – netcyrax May 30 '23 at 12:21
  • Yes, exactly what @netcyrax posted, there aren't any camera permission's required nor there are such on the app's settings (in Android Setings). – tzegian May 30 '23 at 12:26
  • That library appears to be using the dynamically downloaded MLKit models. Those downloads can sometimes fail, and I don't know how the library handles such failures. Have you tried updating the Google Play Servcies app? – Michael May 30 '23 at 12:33
  • @Michael Yes, I am already running on the latest version of Google Play Services. – tzegian May 30 '23 at 13:35
  • I had this issue on my Samsung device, but it worked fine when I tried it on a Google Pixel. Not working on Samsung (or non-Google devices) is .... a severe issue for this library. – netcyrax May 30 '23 at 13:56
  • @netcyrax Hmm, interesting, I have this issue also on a Samsung S21 FE 5G. – tzegian May 30 '23 at 14:53
  • Duplicate SO issue here: https://stackoverflow.com/questions/76358056/getting-a-black-screen-instead-of-a-qr-scanner-while-using-ml-kit-to-scan-barcod And there's an open bug in Google's tracking system (+1 if you are affected): https://issuetracker.google.com/issues/285007312 – netcyrax May 31 '23 at 18:44

0 Answers0