Jenis Kasundra
Jenis Kasundra

Reputation: 583

BiometricPrompt FACE ID authentication is not working in some device

I have implemented biometrics authentication but it is working fine in my Samsung(Android 10) device but not working in one plush and MI device.

In Mi(Android 10) and one plush(Android 10) device, it shows only fingerprint prompt but not showing the option of face authentication

I have set my face id in both devices setting but It is not working. only works in Samsung device.

I have used below code

    executor = ContextCompat.getMainExecutor(this)
            biometricPrompt = BiometricPrompt(this, executor,
                    object : BiometricPrompt.AuthenticationCallback() {
                        override fun onAuthenticationError(errorCode: Int,
                                                           errString: CharSequence) {
                            super.onAuthenticationError(errorCode, errString)
                            Toast.makeText(applicationContext,
                                    "Authentication error: $errString", Toast.LENGTH_SHORT)
                                    .show()
                        }
    
                        override fun onAuthenticationSucceeded(
                                result: BiometricPrompt.AuthenticationResult) {
                            super.onAuthenticationSucceeded(result)
                            Toast.makeText(applicationContext,
                                    "Authentication succeeded!", Toast.LENGTH_SHORT)
                                    .show()
                        }
    
                        override fun onAuthenticationFailed() {
                            super.onAuthenticationFailed()
                            Toast.makeText(applicationContext, "Authentication failed",
                                    Toast.LENGTH_SHORT)
                                    .show()
                        }
                    })
    
            promptInfo = BiometricPrompt.PromptInfo.Builder()
                    .setTitle("Biometric login for my app")
                    .setSubtitle("Log in using your biometric credential")
                    .setConfirmationRequired(true).
                    setNegativeButtonText("login")
                    .build()
    
          
            val biometricLoginButton =
                    findViewById<TextView>(R.id.tvClick)
            biometricLoginButton.setOnClickListener {
                

biometricPrompt.authenticate(promptInfo)
        }

Upvotes: 2

Views: 3036

Answers (1)

Andrey_yog
Andrey_yog

Reputation: 310

It looks like FaceId is recognized as a Weak type of authenticators for Android 11. If a set allowed authenticators like below it begins to work:

new BiometricPrompt.PromptInfo.Builder()
                        .setTitle(getString(R.string.mcm_fingerprint_promt_message, appName))
                        .setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL | BIOMETRIC_WEAK)
                        .build();

Upvotes: 1

Related Questions