我正在使用生物识别认证对话框,但我的 cryptoObject 总是为空。我有一个 fragment,但我也尝试了直接从活动中调用。
以下是我的代码: private Handler biometricPromptHandler = new Handler();
以下是我的代码: private Handler biometricPromptHandler = new Handler();
private Executor executor = command -> biometricPromptHandler.post(command);
private void showBiometricPrompt( String title, String description,
BiometricsCompatCallback compatCallback) {
BiometricPrompt.PromptInfo promptInfo =
new BiometricPrompt.PromptInfo.Builder()
.setTitle(title)
.setSubtitle(description)
.setNegativeButtonText("Cancel")
.build();
BiometricPrompt biometricPrompt = new BiometricPrompt((FragmentActivity) context,
executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode,
@NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
compatCallback.onAuthenticationError(errorCode, errString);
Log.d("onAuthenticationError", ": ");
}
@Override
public void onAuthenticationSucceeded(
@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Log.d("result", ": "+(result.getCryptoObject()));
BiometricPrompt.CryptoObject authenticatedCryptoObject =
result.getCryptoObject();
Log.d("onAuthentionSucceeded", ": "+(authenticatedCryptoObject==null));
if (authenticatedCryptoObject != null) {
cipher = authenticatedCryptoObject.getCipher();
Log.d("onAuthentionSucceeded", ": ");
compatCallback.onAuthenticationSuccessful(cipher);
}else {
Log.d("cipher", "onAuthenticationSucceeded: ");
}
}
@Override
public void onAuthenticationFailed() {
Log.d("onAuthenticationFailed", ": ");
super.onAuthenticationFailed();
compatCallback.onAuthenticationFailed();
}
});
biometricPrompt.authenticate(promptInfo);
}
有人知道我做错了什么吗?