Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a fallback method if fingerprint does not work

I recently moved my project to AndroidX and while implementing fingerprint for the app I am using the Biometric for AndroidX.

implementation 'androidx.biometric:biometric:1.0.0-alpha03'

When a dialog is displayed to use fingerprint for authentication, the dialog has "Cancel" option set as the negative button.

 final BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
            .setTitle("Log into App")
            .setSubtitle("Please touch the fingerprint sensor to log you in")
            .setDescription("Touch Sensor")
            .setNegativeButtonText("Cancel".toUpperCase())
            .build();

As per the android documentation: https://developer.android.com/reference/androidx/biometric/BiometricPrompt.PromptInfo.Builder.html#setNegativeButtonText(java.lang.CharSequence)

Required: Set the text for the negative button. 
This would typically be used as a "Cancel" button, but may be also used
to show an alternative method for authentication, 
such as screen that asks for a backup password.

So instead of "Cancel" button I can say "Use Password" to provide an alternative method incase fingerprint fails, and when user clicks on it I can show another popup dialog where I can let user enter the device password to help retrieve the app password from the Keystore. Is this correct ?

But, what happens if I do not have password set to unlock my phone instead I use a pattern ?

I see that if I use android.hardware.biometrics.BiometricPrompt.Builder instead of androidx.biometric.BiometricPrompt.PromptInfo.Builder, it has a method https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt.Builder.html#setDeviceCredentialAllowed(boolean) for the same purpose, to let user authenticate using other means if fingerprint fails.

Can someone help me understand this ? How I could achieve this with AndroidX as my app is compatible from API 16 onwards. And why does AndroidX does not come back with this fallback method ?

like image 655
nibz Avatar asked Jul 08 '19 05:07

nibz


People also ask

How do you implement fingerprints?

Setting up your fingerprintTap the Settings icon on your Android device and tap Lock screen and security. Scroll down and tap Screen lock type. Add your fingerprint — follow the instructions on your screen and go through the wizard. You'll be prompted to lift and rest your finger on the home button several times.


1 Answers

The setDeviceCredentialAllowed API was recently added in beta01

See the release notes here

https://developer.android.com/jetpack/androidx/releases/biometric

like image 150
Kevin Avatar answered Sep 20 '22 13:09

Kevin