How to fix ML Kit loading problem? - Failed to scan code
Asked Answered
B

3

10

Error on Scan UI loading: "com.google.mlkit.common.MlKitException: Failed to scan code."

I have a problem with my device. When the Scan UI is loading (on GmsBarcodeScanning) i'm getting exception addOnFailureListener. "com.google.mlkit.common.MlKitException: Failed to scan code." In other devices i cannot get the same bug... but more than one for sure. Some one have any workaround to fix it? Tnk

Platform: Android Project: com.google.mlkit.samples.codescanner

Bagasse answered 12/2, 2023 at 19:12 Comment(2)
I have the same issue on some devices. I've reported it in Google's Issue Tracker.Macdonell
This is likely because of the scanner module is not downloaded yet. Can you check whether it's the case by using ModuleInstallClient API? developers.google.com/ml-kit/vision/barcode-scanning/…Sowens
B
7

There is a workaround.

Always send an install request. If the barcode scanner module is already installed it will not be installed again.

Send an urgent module install request

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    val moduleInstall = ModuleInstall.getClient(this)
    val moduleInstallRequest = ModuleInstallRequest.newBuilder()
            .addApi(GmsBarcodeScanning.getClient(this))
            .build()
    moduleInstall
        .installModules(moduleInstallRequest)
        .addOnSuccessListener {
            if (it.areModulesAlreadyInstalled()) {
                // Modules are already installed when the request is sent.
            }
        }
        .addOnFailureListener {
            // Handle failure…
        }
}
Bedim answered 14/8, 2023 at 17:18 Comment(1)
yes its working . with install module. i have tested.Plunger
S
0

Clear the storage data in the google play services app (Settings > Apps > Google Play Service > Storage) and try to update the google play services app. It solved my problem.

Sapphera answered 8/6, 2023 at 9:28 Comment(0)
A
-2

Change metadata value from "barcode_ui" to "barcode" in the AndroidManifest.xml

https://developers.google.com/ml-kit/vision/barcode-scanning/code-scanner?hl=en

says that

<meta-data
      android:name="com.google.mlkit.vision.DEPENDENCIES"
      android:value="barcode_ui"/>

This caused problem.

As stated in this link https://developers.google.com/ml-kit/vision/barcode-scanning/android?hl=en

You must use

<meta-data
          android:name="com.google.mlkit.vision.DEPENDENCIES"
          android:value="barcode" >
Amoreta answered 6/7, 2023 at 12:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.