简体   繁体   English

生物识别提示未显示面部解锁提示

[英]Biometric Prompt not showing prompt for face unlock

I am trying to authenticate my app with fingerprint as well as face unlock depending upon user has setup authentication for his device.Now in my app I want face unlock which is not getting displayed.For that I have removed finger prints but it never comes up.My device supports Android 10.I know oem select what to show ie fingerprint or face prompt.How can i check whether my app supports face unlock.我正在尝试使用指纹和面部解锁来验证我的应用程序,具体取决于用户已为其设备设置了身份验证。现在在我的应用程序中,我想要面部解锁但没有显示。为此,我删除了指纹,但它从未出现过.我的设备支持 Android 10。我知道 oem 选择要显示的内容,即指纹或面部提示。如何检查我的应用程序是否支持面部解锁。 Below is my implementation下面是我的实现

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;

You really can't (I think).你真的不能(我认为)。 You can only determine if it supports a biometric implementation, not which specific one it is (ie you can say it supports biometrics, but not that it supports fingerprint or face recognition).您只能确定它是否支持生物识别实现,而不能确定它是哪一种(即您可以说它支持生物识别,但不能说它支持指纹或面部识别)。 You likely can't see the face recognition option because your device is not capable of STRONG (vs WEAK) biometric through the face id (on Samsungs, for example, the fingerprint is STRONG, but the face id is WEAK).您可能看不到面部识别选项,因为您的设备无法通过面部 ID 进行 STRONG(相对于 WEAK)生物识别(例如,在三星上,指纹较强,但面部 ID 较弱)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM