生物识别提示未显示人脸解锁提示



我正在尝试使用指纹和面部解锁来验证我的应用程序,具体取决于用户为其设备设置了身份验证。现在在我的应用程序中,我想要面部解锁,它没有显示。为此,我删除了指纹,但它从未出现过。我的设备支持Android 10.我知道OEM选择要显示的内容,即指纹或面部提示。如何检查我的应用程序是否支持人脸解锁。 以下是我的实现

Gradle :
implementation "androidx.biometric:biometric:1.0.1"
Code Implementation:
public class MainActivity extends AppCompatActivity {
Button btnHello;
Executor executor;
BiometricPrompt.PromptInfo promptInfo;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
executor = ContextCompat.getMainExecutor(this);
final BiometricPrompt biometricPrompt = new BiometricPrompt(MainActivity.this,
executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode,
@NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, 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();
}
@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();
// Prompt appears when user clicks "Log in".
// Consider integrating with the keystore to unlock cryptographic operations,
// if needed by your app.
Button biometricLoginButton = findViewById(R.id.btnHello);
biometricLoginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
biometricPrompt.authenticate(promptInfo);
}
});
}



}
BiometricManager biometricManager = BiometricManager.from(this);
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;

你真的不能(我认为(。您只能确定它是否支持生物识别实现,而不是哪个特定的实现(即您可以说它支持生物识别,但不能说它支持指纹或面部识别(。您可能看不到人脸识别选项,因为您的设备无法通过面部 ID 进行强(与弱(生物识别(例如,在三星上,指纹是强的,但面部 ID 是弱的(。

最新更新