---
title: How to Add Android Fingerprint Authentication to Your App | ArcTouch
description: ArcTouch’s app development team shares step-by-step instructions for how to add fingerprint authentication to an Android app.
url: "https://arctouch.com/blog/android-fingerprint-authentication"
date_modified: "2025-04-10T19:21:48.051Z"
---
# How to add Android fingerprint authentication to your app

ArcTouch’s app development team shares step-by-step instructions for how to add fingerprint authentication to an Android app.

5 min. read - January 16, 2020

By ArcTouch Team

[](mailto:?subject=Interesting%20blog%20post&body=I%20thought%20you%20might%20like%20this%20blog%20post%20from%20ArcTouch%3A%20https%3A%2F%2Farctouch.com%2Fblog%2Fandroid-fingerprint-authentication)

![Smartphone showing a fingerprint scan](/_next/image?url=https%3A%2F%2Fimages.ctfassets.net%2Fefnbmai9c55m%2F2iMiCZhfuHD6KTZfDL32BS%2F6af04a45e84239934bf2b63d2525ac97%2Fsmartphone-with-finger-scan-vector&w=3840&q=75)

The experience of fingerprint authentication is really delightful. Once you have used a phone with a fingerprint scanner, it’s difficult to imagine going back to one without it. Remember how annoying it was to provide your password every time you needed to access your bank’s app? And every time you needed to perform a sensitive operation, like an account transfer? And even rapidly drawing some random lines to unlock your phone while fearing someone getting a glimpse of it?

As an Android app developer and an app user, I know just how big of a difference fingerprint authentication can make for the user experience. In this post, we provide step-by-step instructions for how developers can add Android fingerprint authentication into apps.

## A bit of Android fingerprint authentication history

Fingerprint authentication has been officially supported by Android since API 23 (M). At that time, the feature was supported through the `FingerprintManager ` API. Although there was the [material.io](https://material.io/design/platform-guidance/android-fingerprint.html) UI standard for it, there wasn’t a unified authentication dialog — which meant app developers were wildly inconsistent how they supported it.

API 28 added the `BiometricPrompt`, a unified authentication dialog, and `FingerprintManager` was marked as deprecated. AndroidX’s BiometricPrompt reached beta in August 2019! ?

All code snippets provided in this guide were made using AndroidX’s `BiometricPrompt` (at the time of writing this post, the latest version is 1.0.0-beta01), so make sure to add its dependency in your app’s build.gradle:

1

```
implementation "androidx.biometric:biometric:$biometric_version"
```

## Step by step: Implementing Android fingerprint authentication

While improving the UX is a great reason to implement fingerprint authentication in an Android app, companies must also take great care to protect features that run behind fingerprint authentication. Accessing them can only occur after the Android system confirms that the individual using the device is recognized and authorized.

### Step 1: Check device support

First of all, check if the device supports fingerprint authentication by calling:

1

```
BiometricManager.from(context).canAuthenticate()
```

This method returns an `int`, which can have one of these values:

1

2

3

4

```
public static final int BIOMETRIC_ERROR_HW_UNAVAILABLE = 1;
public static final int BIOMETRIC_ERROR_NONE_ENROLLED = 11;
public static final int BIOMETRIC_ERROR_NO_HARDWARE = 12;
public static final int BIOMETRIC_SUCCESS = 0;
```

Obviously, you should only show the option for biometric authentication if it’s available on the device, that is, if `canAuthenticate()` returns `BIOMETRIC_SUCCESS`. Some smartphones that had fingerprint scanners before Android officially supported it will return `BIOMETRIC_ERROR_HW_UNAVAILABLE`. Generally speaking, those smartphones were released in APIs before 23 and could be updated to 23 (like the Samsung Galaxy Note 4). They can’t be used by the official API because they don’t attend to some specifications given by the [Android M Compatibility Definition Document](https://source.android.com/compatibility/6.0/android-6.0-cdd), including this one:

_“MUST have a hardware-backed keystore implementation, and perform the fingerprint matching in a Trusted Execution Environment (TEE) or on a chip with a secure channel to the TEE.”_

### Step 2: Create a BiometricPrompt instance

We need to create an instance of `BiometricPrompt` that will be responsible to prompt the user for authentication. Its constructor has three parameters:

* `Fragment` or `FragmentActivity`: A reference to the client’s activity
* `Executor`: An executor to handle callback events
* `BiometricPrompt.AuthenticationCallback`: An object to receive authentication events

The first two arguments are quite direct. For the first argument, use the calling `FragmentActivity` or `Fragment`. For the second one, you should use the executor that fits best your needs. Here, for simplicity, we’re going to use the `mainExecutor`.

The third argument deserves more attention. It will receive the authentication results (such as if there was an error, or if it was canceled or successful) and can give us a `CryptoObject` associated with the authentication. We’ll come back to the `CryptoObject` in a later blog post, but for now, here’s a simple example which doesn’t need it:

1

2

3

4

5

```
val biometricPrompt = BiometricPrompt(
  this, // assuming it's being called inside an Activity
  mainExecutor,
  callback
)
```

For the `callback`, we can use:

 1

 2

 3

 4

 5

 6

 7

 8

 9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

```
val callback = object : BiometricPrompt.AuthenticationCallback() {

  override fun onAuthenticationSucceeded(
    result: BiometricPrompt.AuthenticationResult
  ) {
    // user authenticated
    // now you can allow him to perform that sensible action
    someSensibleAction()
  }

  override fun onAuthenticationError(
    errorCode: Int,
    errString: CharSequence
  ) {
    // called when an unrecoverable error has been encountered
    // and the operation is complete
    // example: user clicked the negative button or
    // tried too many times and is locked up
  }

  override fun onAuthenticationFailed() {
    // called when biometric was valid but not recognized
    // example: the user tried to authenticate
    // with a finger that isn't registered
  }

}
```

The dialog displays the correct message (`errString`) by itself while taking into consideration the user’s `Locale`, so it’s pretty much automatic. You might need to redirect the user to some other flow in case of an error. The possible error codes are listed [here](https://developer.android.com/reference/androidx/biometric/BiometricPrompt.html#constants%5F2). It’s worth noting that when the user presses the negative button, it’ll result in `onAuthenticationError` with `ERROR_NEGATIVE_BUTTON`.

### Step 3: Build the authentication dialog

The dialog is built using the `BiometricPrompt.PromptInfo.Builder`. It follows the commonly seen builder pattern and can be as simple and direct as:

1

2

3

4

```
val promptInfo = BiometricPrompt.PromptInfo.Builder()
  .setTitle("Title")
  .setNegativeButtonText("Negative Button Text")
  .build()
```

But it also provides some optional methods for displaying a description and assistive text, such as allowing the device’s credential authentication (PIN, pattern or password). Those methods are described [here](https://developer.android.com/reference/androidx/biometric/BiometricPrompt.PromptInfo.Builder.html) in the documentation. Notice that if you enable the use of the device’s credentials to authenticate, you can’t set a negative button.

### Step 4: Authenticate

Now, with two objects at hand, we can call `biometricPrompt.authenticate(promptInfo)` and perform the actual authentication. This will display the authentication dialog and send its events to the `callback` specified. Here is a simple example of how it might look:

That is a simple way to implement fingerprint authentication in Android.

## Need help with your Android app project?

ArcTouch’s [Android developers](/android-developers) have been building lovable apps for more than a decade. If you need help with your Android project or some advice on how to support the latest features in Android 10, [contact us](/contact) to set up a free consultation.

## Article Author:

[AT | ArcTouch Team | ArcTouch Employees](/blog/author/arctouch-team)

## Tags:

[Android](/tag/android) [Android Apps](/tag/android-apps) [Best Practices](/tag/best-practices) [Developer Tips](/tag/developer-tips) [Programming](/tag/programming)

## Subscribe for more insights

Get our newsletter in your inbox.

## Related posts

[12 web accessibility best practices: A starter list | ArcTouch shares 12 best practices that provide a great starting point for building accessible web experiences. | 5 min. read - April 16, 2024](/blog/web-accessibility-best-practices) [Injecting AI into software development — an ArcTouch blog series | The ArcTouch design and development team shares how to use AI to build lovable apps and websites — better and faster. | 5 min. read - April 9, 2024](/blog/ai-software-development)

## Contact us.

### Let's build something lovable. Together.

We help companies of all sizes build lovable apps, websites, and connected experiences.
