【发布时间】:2021-10-03 05:52:24
【问题描述】:
我正在尝试构建一个具有生物特征身份验证(指纹)的应用程序,但我在使用否定按钮时遇到了一些问题。 该按钮有效,但由于某种原因完全不可见。 This is how the app shows
我在 Java 中使用 BiometricPrompt 和 BiometricManager。
编辑:似乎该按钮在不属于我的任何其他手机中正常显示 我用的是小米红米 Note 8。
但这是我正在使用的代码:
private void initViews()
{
biometricManager = BiometricManager.from(this);
passwordEditText=findViewById(R.id.passwordText);
loginButton=findViewById(R.id.loginButton);
switch (biometricManager.canAuthenticate()) {
case BiometricManager.BIOMETRIC_SUCCESS:
Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
break;
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
Log.e("MY_APP_TAG", "No biometric features available on this device.");
break;
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
Log.e("MY_APP_TAG", "Biometric features are currently unavailable.");
break;
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
Log.e("MY_APP_TAG", "The user hasn't associated " +
"any biometric credentials with their account.");
break;
}
executor = ContextCompat.getMainExecutor(this);
biometricPrompt = new BiometricPrompt(EnterYourPassActivity.this,
executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode,
@NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
if(errString.equals("Use account password"))
{
passwordEditText.setVisibility(View.VISIBLE);
}
else
{
Log.d("MY_APP_TAG",""+errString);
Toast.makeText(getApplicationContext(),
"Authentication error: " + errString, Toast.LENGTH_SHORT)
.show();
}
}
@Override
public void onAuthenticationSucceeded(
@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Toast.makeText(getApplicationContext(),
"Authentication succeeded!", Toast.LENGTH_SHORT).show();
Intent seeingFiles = new Intent(EnterYourPassActivity.this, SeeingFilesActivity.class);
startActivity(seeingFiles);
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
Toast.makeText(getApplicationContext(), "Authentication failed",
Toast.LENGTH_SHORT)
.show();
}
});
promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Use account password")
.build();
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
biometricPrompt.authenticate(promptInfo);
}
});
}
【问题讨论】:
-
您可以通过 xml(
visible属性,如果我没记错的话)或代码(button.setVisibility(View.VISIBLE))设置按钮 visibility。最后检查按钮的颜色是否与背景区域的颜色相同。 -
请通过添加代码来编辑您的问题,例如您如何构建对话框。看看这是否适合您:dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setBackground(R.color.yourcolor );
-
谢谢,帖子已经编辑了
-
我在三星 Galaxy S8、Android 9 上看到了同样的问题。没有要操作的对话框对象,所以我不清楚如何访问此按钮。
标签: java android android-biometric-prompt android-biometric