Android BiometricManager class, Biometric authentication solution for Android

Chetan Gaikwad
3 min readFeb 15, 2020

--

Preface

What is Biometric authentication?

Why it is required?

What're the advantages over other authentication mechanisms?

How to implement it?

Conclusion

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.

Implementation

let’s code

Android 10

  • Introduces the BiometricManager class that developers can use to query the availability of biometric authentication.
  • Includes fingerprint and face authentication integration for BiometricPrompt

Android 9

  • Includes fingerprint integration only for BiometricPrompt.
  • Deprecates the FingerprintManager class. If your bundled and system apps use this class, update them to use BiometricPrompt and BiometricManager instead.
  1. 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

  • Context
  • 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

Sources
https://source.android.com/security/biometric

https://developer.android.com/training/sign-in/biometric-auth

Github repo:
https://github.com/gaikwadChetan93/Android-Biometric-Auth

My portfolio: https://droid-learn.com/

--

--

No responses yet