Android:如何在BiometricPrompt上仅指定面部识别对话框?

问题描述

我需要通过touchid和faceid实现生物识别登录,从而允许用户选择他/她要启用的触摸或面部识别。

我使用最新的android库(androidx.biometric:biometric)来实现此目的,但是在promt上触摸和面部分开时遇到了麻烦。

下图显示了我的问题。

enter image description here

这是我的代码:

private fun displayBiometricPrompt(
    activity: FragmentActivity,biometricCallback: BiometricCallback
) {
    context.let {
        val biometricPrompt = BiometricPrompt(
            activity,it?.mainExecutor!!,object : BiometricPrompt.AuthenticationCallback() {

                override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
                    super.onAuthenticationSucceeded(result)
                    biometricCallback.onAuthenticationSuccessful()
                }

                override fun onAuthenticationError(errorCode: Int,errString: CharSequence) {
                    super.onAuthenticationError(errorCode,errString)
                    biometricCallback.onAuthenticationError(errorCode,errString)
                }

                override fun onAuthenticationFailed() {
                    super.onAuthenticationFailed()
                    biometricCallback.onAuthenticationFailed()
                }
            }
        )
        biometricPrompt.authenticate(
            BiometricPrompt.PromptInfo.Builder()
                .setTitle(title)
                .setSubtitle(subtitle)
                .setDescription(description)
                .setConfirmationRequired(false)
                .setNegativeButtonText(negativeButtonText)
                .build()
        )
    }
}

解决方法

无法指定类型。虹膜和面部扫描仪仅受Android 10支持。在此之前,只有指纹可用。

如果设备具有多个传感器,则将每个传感器定义为“弱”或“强”,“可靠”。生物识别API选择最可靠的传感器,并默认将其提供给用户。

相关问答

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