Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Add Fingerprint Authentication in Your Android App?

  • Difficulty Level : Hard
  • Last Updated : 16 Feb, 2021

Now a day, we have seen that most of our Android phone contains fingerprint authentication. And we can implement that fingerprint authentication in our app so to secure our app as much as we can. In this article, we will take a look at the implementation of fingerprint authentication.

What we are going to build in this article?  

We will be building a simple application in which we will be displaying an image of a fingerprint and a login button. After clicking on the login button we will apply our fingerprint. And if that same fingerprint is added into the Security setting then we will get login success. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using the Java language. 

Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Add dependency and JitPack Repository

Navigate to the Gradle Scripts > build.gradle(Module:app) and add the below dependency in the dependencies section.   

implementation ‘androidx.biometric:biometric:1.0.1’

Add the JitPack repository to your build file. Add it to your root build.gradle at the end of repositories inside the allprojects{ } section.

allprojects {

 repositories {


   maven { url “” }



After adding this dependency sync your project and now we will move towards its implementation.  

Step 3: Working with the AndroidManifst.xml file

Add the following line inside your AndroidManifst.xml file.

<uses-permission android:name=”android.permission.USE_BIOMETRIC”/>

Step 4: Working with the activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 


<?xml version="1.0" encoding="utf-8"?>
        android:text="GFG | First App"
        android:textSize="30dp" />
        android:text="Use your fingerprint to login"
        android:textSize="18sp" />
        android:src="@drawable/ic_fingerprint_black_24dp" />
        android:textSize="18sp" />
        android:text="Login" />

Create a new Drawable Resource File and name the file as the background. Below is the code for the background.xml file.


<?xml version="1.0" encoding="utf-8"?>
        android:startColor="#29DA2E" />

Step 4: Working with the file

Go to the file and refer to the following code. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;
import java.util.concurrent.Executor;
public class MainActivity extends AppCompatActivity {
    protected void onCreate(Bundle savedInstanceState) {
        // Initialising msgtext and loginbutton
        TextView msgtex = findViewById(;
        final Button loginbutton = findViewById(;
        // creating a variable for our BiometricManager
        // and lets check if our user can use biometric sensor or not
        BiometricManager biometricManager = androidx.biometric.BiometricManager.from(this);
        switch (biometricManager.canAuthenticate()) {
            // this means we can use biometric sensor
            case BiometricManager.BIOMETRIC_SUCCESS:
                msgtex.setText("You can use the fingerprint sensor to login");
            // this means that the device doesn't have fingerprint sensor
            case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
                msgtex.setText("This device doesnot have a fingerprint sensor");
            // this means that biometric sensor is not available
            case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
                msgtex.setText("The biometric sensor is currently unavailable");
            // this means that the device doesn't contain your fingerprint
            case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
                msgtex.setText("Your device doesn't have fingerprint saved,please check your security settings");
        // creating a variable for our Executor
        Executor executor = ContextCompat.getMainExecutor(this);
        // this will give us result of AUTHENTICATION
        final BiometricPrompt biometricPrompt = new BiometricPrompt(MainActivity.this, executor, new BiometricPrompt.AuthenticationCallback() {
            public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
                super.onAuthenticationError(errorCode, errString);
            public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
                Toast.makeText(getApplicationContext(), "Login Success", Toast.LENGTH_SHORT).show();
                loginbutton.setText("Login Successful");
            public void onAuthenticationFailed() {
        // creating a variable for our promptInfo
        final BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder().setTitle("GFG")
                .setDescription("Use your fingerprint to login ").setNegativeButtonText("Cancel").build();
        loginbutton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {


GitHub link:

My Personal Notes arrow_drop_up
Recommended Articles
Page :