Crash with Android/Kotlin QR Scanner App and the latest version of Google ML Kit Scan Barcode

前端 未结 1 1663
粉色の甜心
粉色の甜心 2021-01-27 06:23

I am trying to make an app which reads QR images and get the data from the image. I am using the latest version of the google machine learning kit for scan barcodes and followin

相关标签:
1条回答
  • 2021-01-27 06:50

    So if we look at the code:

    1. Create InputImage from ImageProxy
    2. scanner.process(image).addWhateverListener(etc etc) but not onComplete
    3. imageProxy.close

    Why would this not work? Step 2 is async so it takes say a fraction of time before it is executed but in the meantime, step 3 kicks in and clear the image - no image to detect. The solution is to use addOnCompleteListener to close the image:

        scanner.process(image)
            .addOnFailureListener { // Some code}
            .addOnSuccessListener { // Some more code}
            .addOnCompleteListener {
                // Close the image
                imageProxy.close()}
    

    BTW this got me the first time too and we are thinking about adding better debug message than "Image is already close".

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