【问题标题】:Biometrics prompt works with API 21+ but API 19 shows error生物识别提示适用于 API 21+,但 API 19 显示错误
【发布时间】:2019-12-19 16:28:02
【问题描述】:

所以我在使用设备锁定方法的应用程序上进行了应用程序锁定 - 我使用支持所有 android 版本的 Biometrics 1.0.1,但是在 KitKat 上,当我按下解锁时,它显示 tihs toast:

身份验证错误:此设备没有指纹传感器。

即使我使用 .setDeviceCredentialAllowed(true) 如果没有指纹可用,它也应该使用设备 PIN 或图案。

keyguardManager.isKeyguardSecure 返回 true

promptInfo = BiometricPrompt.PromptInfo.Builder()
            .setTitle("Biometric login for my app")
            .setSubtitle("Log in using your biometric credential")
            .setDeviceCredentialAllowed(true)
            .build()

        // Prompt appears when user clicks "Unlock".
        val biometricLoginButton = unlock_button
        biometricLoginButton.setOnClickListener {
            biometricPrompt.authenticate(promptInfo)
        }

【问题讨论】:

    标签: android kotlin android-biometric-prompt


    【解决方案1】:

    setDeviceCredentialAllowed()方法只支持Api 21+

    因为这个api在内部使用KeyguardManager.createConfirmDeviceCredentialIntent(CharSequence, CharSequence) 此方法在API 21 上添加并在API 29 上弃用Reference

    来自Api docs

    在 P 及以下版本中,一旦显示设备凭据提示,BiometricPrompt.cancelAuthentication() 将不起作用,因为库内部启动 KeyguardManager.createConfirmDeviceCredentialIntent(CharSequence, CharSequence),它没有用于取消的公共 API。

    【讨论】:

    • 那么这是否意味着低于 API 21 BiometricPrompt 没有向后兼容的形式?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 2019-06-09
    相关资源
    最近更新 更多