Implementing biometric authentication in Android

  • Use of BiometricPrompt and Credential Manager to manage secure and personalized access.
  • Implementation of security layers using CryptoObject to protect sensitive data.
  • Integration of liveness detection systems and AI to combat fraud and impersonation.
  • Compliance with Android CDD security standards and privacy regulations.

Implementing biometric authentication in Android

Today, protecting private information or exclusive app content doesn't have to be a headache for the user. The implementation of biometric authentication has become the key tool for achieving that difficult balance between rock-solid security and a user experience that isn't tedious, similar to how a secure folder works to protect private files.

If you're considering how to integrate these features into your project, the first thing to know is that Android offers a very robust ecosystem. It's not just about requesting a fingerprint, but about managing access flows that adapt to the user's device, ensuring data security regardless of whether the phone is a high-end model or a more modest one.

Essential tools: Credential Manager and Biometric Prompt

To get off to a good start, it's essential to understand the available tools. As a general rule, Credential Manager is the best option when a user accesses the app for the first time on a device. For subsequent accesses, where only a quick reauthorization is needed, you can choose between Biometric Prompt or the aforementioned credential manager.

The main advantage of Biometric Prompt is that it allows for greater customization of the dialog, while Credential Manager offers a simpler, unified implementation for both workflows. It's worth noting that the Biometric library has replaced the older FingerprintManager API, which became obsolete some time ago.

Types of authenticators and security levels

Protect your privacy with NetGuard
Related article:
Activate essential security settings on Android

Not all biometric sensors are created equal, and Android understands this by classifying authenticators through the BiometricManager.Authenticators interface . Depending on your app's needs, you can declare the following levels:

  • BIOMETRIC_STRONGThis refers to class 3 methods, which are the safest and strictest.
  • BIOMETRIC_WEAKClass 2 authenticators, which offer an acceptable balance but lower security.
  • DEVICE_CREDENTIALThis is where traditional screen lock methods come in, such as PIN, pattern, or password.

It's important to remember that for any of these to work, the user must have previously configured a locking method, such as knowing How to choose a 6-digit PIN on AndroidIf not, the system will automatically launch the biometric enrollment flow so that the user creates their credentials. To configure this in the code, the method is used. setAllowedAuthenticators(), even allowing you to combine several types of access.

Step-by-step implementation flow

Guide to Hiding Sensitive Apps in Private Space on Android
Related article:
Private Space Guide: Hide sensitive apps on Android

Once you have decided what level of security you require, the next step is check availability of said sensors using the method canAuthenticate()If the device does not have the data recorded, you can invoke the action ACTION_BIOMETRIC_ENROLL to direct the user to the system settings and configure their biometrics.

To deploy the login request, you must add the androidx.biometric library dependency to your build.gradle file. Once installed, you can launch the system dialog from your activity or fragment. Using this standard dialog is vital, as it builds user trust by presenting an interface consistent with the rest of the operating system.

After successful authentication, you can use the method getAuthenticationType() to know exactly How was the user identified?, whether it was through biometric data or via device credentials.

Advanced security with cryptographic solutions

If you want to take security to the next level and go beyond a simple access check, integrating CryptoObject is ideal . This allows cryptographic operations (such as decrypting a key) to depend directly on successful biometric authentication.

How to password-protect selected apps
Related article:
Best password managers for Android

The Android framework supports objects like Signature, Cipher, Mac and KeyAgreementFor example, if you use a Cipher object along with a SecretKey, your app will be able to perform the process of data encryption and decryption sensitive only after the user has placed their fingerprint or face. Depending on the settings KeyGenParameterSpecYou can force authentication to be strictly biometric or allow the device PIN to serve as a backup.

There are also so-called usage-based authentication keys . These are perfect for critical transactions, such as large bank transfers, as they require the user to authenticate every time they access data protected by that specific key, regardless of whether the app has been unlocked before.

Optimizing the experience and detecting fraud

Sometimes, for low-risk actions, we can prevent the user from having to press a confirmation button. To do this, simply pass the value false to the method setConfirmationRequired()allowing for much smoother access, especially with passive methods such as facial recognition.

However, in the real world, threats like deepfakes or printed photographs exist. This is where liveness detection , both active and passive, comes into play. Using sophisticated AI makes it possible to differentiate a real human being from an impersonator, ensuring that the person trying to access the account is indeed the account holder.

To avoid a frustrating experience, it's crucial to offer clear instructions and immediate feedback . If a verification fails due to poor image quality or an insufficient vividness score, the app should inform the user constructively so they know how to correct it on the next attempt.

Regulations, Privacy and the Biometric HAL

Why is Android AV slow after an update?
Related article:
Which Android settings should you check every few months for security?

From a low-level development perspective, biometric HAL guidelines are strict to prevent data leaks. Raw biometric data must never leave the secure isolated environment, such as the Trusted Execution Environment (TEE) or the secure hardware component.

All storage must be encrypted with device-specific keys, and SELinux policies must be implemented to restrict hardware access. Furthermore, it is essential to comply with international regulations such as GDPR and CCPA , always obtaining explicit user consent before processing any sensitive data.

The Android architecture has evolved significantly from version 9 to 12, introducing improvements such as localized authentication strings through BiometricManager.Strings, which allow the dialogue messages to be tailored exactly to the sensor the device has (for example, saying "Use face" instead of a generic "Use biometrics").

The key to success lies in combining official Android APIs with modern security standards , robust encryption, and an intuitive interface that doesn't sacrifice protection for speed. By properly integrating the credential manager and Class 3 security levels, a secure and professional application is achieved that protects user privacy at all times.

Activate full privacy mode on your mobile device
Related article:
Activate full privacy mode on your Android phone

Add as preferred source in Google