Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 944
Diez de Ulzurrun Rafael Emmanu Avatar asked Mar 17 '26 05:03

Diez de Ulzurrun Rafael Emmanu


1 Answers

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…
        }
}
like image 122
Oliver Kranz Avatar answered Mar 19 '26 00:03

Oliver Kranz