DEV Community

Cover image for Biometric Authentication: Steps to Implement in Android
Emily3103
Emily3103

Posted on

Biometric Authentication: Steps to Implement in Android

This article explores the use of google Biometric features to implement biometric authentication in a system. Using an API feature ‘BiometricPrompt’. Biometric Prompt allows building a biometric authentication process in Android. Biometric Prompt class manages a system-provided dialog

Biometric fingerprint authentication is supported a long time ago by Android 6.0. This new biometric technology is more promising in the sense if authenticating the end-users with more accurate results. Online identity verification APIs use biometric technology to identify and verify the end-users, due to the growing roots of biometrics in the era of remote verification. A consistent level of security is adopted in the shape of biometrics whose need has made it compatible to fit in a large number of devices.

#1 . Add permissions

In the AndroidManifest.xml, add permissions to use biometric and specifically the fingerprint permission.

manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.an.biometric"

uses-permission android:name = “android.permission.USE_BIOMETRIC”
uses-permission android:name = “android.permission.USE_FINGERPRINT”

#2 . Check the device Compatibility

Make sure that the device is compatible with biometric technology. Make sure that it has 6.0 or greater than 6.0 version, also holds a fingerprint sensor. User permission is needed to grant access to the fingerprint sensor and at least one fingerprint is registered to the device.

/* Check the android version
*Fingerprint supporting device check
*If minSdkversion is >= 23, then there is no need to apply the below check
*/

Public class Bio_utils{

Public static boolean isBioPromptEnabled(){
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P);
}

/Check fingerprint sensor check/

Public static boolean sdkversioncheck(){
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M);
}

/* Similarly embed checks of hardware support, fingerprint availability in device, and permission grant check*/
}

#3 . Biometric Prompt Dialog

A biometric prompt dialog is only displayed in Android P. After ensuring the above checks, use Biometric Prompt builder to:

setTitle(): set display title
setSubtitle(): set the display subtitle
setDescription(): set the description of dialog
setNegativeButton(): set text for negative button

Among the above list, setTitle() and setNegativeButton are required fields and others are optional.

#4 . BiometricPrompt.AuthenticationCallback

To listen to the authentication events after certain functionality, user needs to respond to such events. On the basis of that response, BiometricPrompt.AuthenticationCallback is used. Below are the four methods:

OnAuthenticationSucceeded: when the fingerprint successfully matches the ones that are registered
OnAuthenticationFailed: when the fingerprint does not match the ones that are registered in the device, at that time this callback prompts
OnAuthenticationError: when an error has occurred which is hard to handle and has encountered the completion of the authentication process
OnAuthenticationHelp: This method is used when a non-fatal error does occur during the authentication process

#5 . Create a UI Code


Create UI code that seems similar to the dialog of Biometric Prompt. Set the title, subtitle, update status, set description and insert Button. Proceed with the basic UI and enter detailed fanciness later.
These above steps are the basics of implementing a biometric authentication system in Android.

Top comments (0)