Аутентификация BiometricPrompt FACE ID не работает на некоторых устройствах

Я реализовал биометрическую аутентификацию, но она отлично работает на моем устройстве Samsung (Android 10), но не работает на одном плюшевом и MI-устройстве.

В Mi (Android 10) и одном плюшевом (Android 10) устройстве отображается только запрос отпечатка пальца, но не отображается опция аутентификации по лицу.

Я установил свой идентификатор лица в настройках обоих устройств, но он не работает. работает только в устройстве Samsung.

Я использовал код ниже

    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)
        }

person Jenis Kasundra    schedule 08.02.2021    source источник


Ответы (1)


Похоже, FaceId признан слабым типом аутентификаторов для Android 11. Если набор разрешил аутентификаторы, как показано ниже, он начинает работать:

new BiometricPrompt.PromptInfo.Builder()
                        .setTitle(getString(R.string.mcm_fingerprint_promt_message, appName))
                        .setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL | BIOMETRIC_WEAK)
                        .build();
person Andrey_yog    schedule 19.04.2021
comment
setAllowedAuthenticators (....) метод недоступен - person Arun PK; 16.07.2021