我正在使用 android 提供的 BiometricPrompt 类在我们的应用程序中提供生物识别身份验证,它工作正常,但是当我点击手机的后退按钮时,会显示空白页面。相反,我希望应用程序在单击后退按钮时关闭。任何指针都会有所帮助。,
public class FingerprintLoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
BiometricPrompt biometricPrompt = new BiometricPrompt(this, Executors.newSingleThreadExecutor(), new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
if (errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON) {
// user clicked negative button
} else {
// TODO: Called when an unrecoverable error has been encountered and the operation is complete.
}
}
@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
//TODO: Called when a biometric is recognized.
Context.Fingerprint = true;
Intent fingerprintIntent = new Intent(FingerprintLoginActivity.this, MainActivity.class);
fingerprintIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(fingerprintIntent);
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
//TODO: Called when a biometric is valid but not recognized.
}
});
BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("touch to fingerprint scanner")
.setNegativeButtonText("Cancel")
.build();
biometricPrompt.authenticate(promptInfo);
}
}