【发布时间】:2019-07-08 05:16:13
【问题描述】:
我最近将我的项目移至 AndroidX,在为应用程序实现指纹时,我正在使用 AndroidX 的 Biometric。
implementation 'androidx.biometric:biometric:1.0.0-alpha03'
当显示使用指纹进行身份验证的对话框时,该对话框将“取消”选项设置为否定按钮。
final BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Log into App")
.setSubtitle("Please touch the fingerprint sensor to log you in")
.setDescription("Touch Sensor")
.setNegativeButtonText("Cancel".toUpperCase())
.build();
Required: Set the text for the negative button.
This would typically be used as a "Cancel" button, but may be also used
to show an alternative method for authentication,
such as screen that asks for a backup password.
因此,我可以说“使用密码”代替“取消”按钮,以提供另一种方法以防指纹失败,当用户单击它时,我可以显示另一个弹出对话框,让用户输入设备密码以帮助检索密钥库中的应用程序密码。它是否正确 ?
但是,如果我没有设置密码来解锁我的手机,而是使用了图案,会发生什么?
我看到如果我使用 android.hardware.biometrics.BiometricPrompt.Builder 而不是 androidx.biometric.BiometricPrompt.PromptInfo.Builder,它有一个方法 https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.Builder.html#setDeviceCredentialAllowed(boolean) 出于同样的目的,如果指纹失败,让用户使用其他方式进行身份验证。
有人可以帮助我理解这一点吗?我如何使用 AndroidX 实现这一点,因为我的应用程序从 API 16 开始兼容。为什么 AndroidX 不使用这种回退方法?
【问题讨论】:
-
我使用的是 alpha04,但 setDeviceCredentialAllowed() 不可用。我认为使用 AndroidX 组件的整个想法是避免使用 SDK 级别的代码......也许 Google 计划在未来添加它?
标签: android fingerprint androidx android-fingerprint-api android-biometric-prompt