What is Biometric authentication?
Biometric authentication is a security process that relies on the unique biological characteristics of an individual such as Fingerprints, Facial characteristics, Voice, Eye retina.
The Android framework includes face and fingerprint biometric authentication. Android can be customized to support other forms of biometric authentication (such as Iris).
Why it is required in Android and advantages over other auth mechanisms?
Biometric authentication is safe as compared to other authentication mechanisms available in Android like Pin, Pattern or Password because other authentication mechanisms can get compromised alike Biometric Authentication where you can only unlock the device.
Digital transactions via phone are growing at a rocket speed so ensuring the safety of the device is one of the important aspects of today's technology.
- Introduces the
BiometricManagerclass that developers can use to query the availability of biometric authentication.
- Includes fingerprint and face authentication integration for
- Includes fingerprint integration only for
- Deprecates the FingerprintManager class. If your bundled and system apps use this class, update them to use
- Let’s import the dependency
2. Check if your device supports biometric authentication
If you want some more information about support
3. BiometricPrompt class is used to prompt a system dialog to the user requesting to authenticate using biometric credentials. Let’s initialize BiometricPrompt class first, it has 3 parameter
- Executor: Allows you to specify a thread on which your callbacks should be run
- AuthenticationCallback: An abstract class which have 3 methods onAuthenticationError(Called when an unrecoverable error has been encountered and the operation is complete)
onAuthenticationSucceeded(Called when a biometric is recognized)
onAuthenticationFailed(Called when a biometric is valid but not recognized)
4. Our BiometricPrompt object is ready now we have to customize the PromptInfo class to show a dialog explaining why authentication is required.
setDeviceCredentialAllowed(true): The user will first be prompted to authenticate with biometrics, but also given the option to authenticate with their device PIN, pattern, or password.
5. Final step just call
Now run the app