BiometricPrompt FACE ID 身份验证在某些设备中不起作用

问题描述

我已经实施了生物识别身份验证,但它在我的三星(Android 10)设备上运行良好,但在一个毛绒和 MI 设备上却无法运行。

小米(Android 10)和一个毛绒(Android 10)设备,只显示指纹提示,不显示人脸认证选项

我在两个设备设置中都设置了我的面部 ID,但它不起作用。仅适用于三星设备。

我使用了以下代码

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

解决方法

看起来 FaceId 被识别为 Android 11 的弱类型身份验证器。 如果一组允许的身份验证器如下所示,它开始工作:

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...