在Android 11中,Google更新了生物识别API以提高安全性。在使用生物识别功能时可能会遇到问题。例如,生物识别提示对话框中的生物识别图标未显示。解决此问题的方法如下:
biometricPrompt = new BiometricPromptCompat.Builder(this)
.setTitle(title)
.setDescription(subtitle)
.setNegativeButton(getString(R.string.cancel), context.getMainExecutor(),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
// Handle cancel action
}
})
.build();
biometricPrompt.authenticate(new BiometricPromptCompat.AuthenticationCallbackCompat() {
@Override
public void onAuthenticationError(int errorCode, CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
// Handle authentication errors
}
@Override
public void onAuthenticationSucceeded(BiometricPromptCompat.AuthenticationResultCompat result) {
super.onAuthenticationSucceeded(result);
// Handle authentication success
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
// Handle authentication failed
}
});
以上解决方法适用于Android 11及以上版本中生物识别提示对话框中生物识别图标未显示的问题。