我在我的 Android 应用程序中使用新的 BiometricPrompt 从以下文学
implementation 'androidx.biometric:biometric:1.0.0-rc01'
加载活动时,我能够成功显示 BiometicPrompt。
我的问题是,如果我将 Prompt 保持理想状态 30-60 秒,或者如果我将应用程序更改为后台,或者当应用程序再次出现时 Prompt 正在显示时我锁定和解锁屏幕 BiometricPrompt 被解雇/不显示。我无法确定问题是否与我的执行人有关,请帮忙。下面是我的代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Executor executor = Executors.newFixedThreadPool(2);
final BiometricPrompt biometricPrompt = new BiometricPrompt(this,
executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
}
@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
navigateHome();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
});
final BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Authenticate")
.setSubtitle("Unlock with your fingerprint")
.setNegativeButtonText("Cancel")
.build();
biometricPrompt.authenticate(promptInfo);
}
2019 年 2 月 13 日更新
我更新到
implementation 'androidx.biometric:biometric:1.0.1'
并更改执行者如下
Executor executor = ContextCompat.getMainExecutor(this);
现在大部分的问题都解决了,除了一加设备带屏下指纹扫描仪(6T及以上机型)。在提供不正确的手指扫描(第一次本身)时,提示正在调用onAuthenticationFailed()而不是onAuthenticationError(..)