How to Add Fingerprint Authentication in Android using android studio

0 917

Fingerprint Authentication in Android

Fingerprint Authentication in AndroidAndroid is the most popular mobile operating system in date. Especially Android 6.0 provides some interesting new features for its users and developers. Let me explain you about them:

  • Fingerprint Authentication
  • Confirm Credential
  • App Linking
  • Auto Backup for Apps
  • Direct Share
  • Voice Interactions
  • Assist API
  • Adoptable Storage Device
  • And Much more

Today we will discuss one of the features named: ‘Fingerprint Authentication’. Android 6.0 provides new APIs to help you authenticate users through fingerprint scans on devices that support this feature. I will explain you to implement Fingerprint Authentication in your Application. For authenticating users through fingerprint sensor, create an instance of the newly implemented FingerprintManager class by calling authenticate() method. You should run your App on the suitable device that has a fingerprint sensor. And you have to implement the user interface on your app for the fingerprint authentication. In your UI you have to use the standard Android fingerprint icon. Every App must authenticate the user’s fingerprint individually if multiple Apps use the fingerprint authentication.

Is Using Fingerprint Authentication a Good Idea ? and Benefits of using Fingerprint Authentication

  • Your fingerprints will never alter or lost, whatever the conditions are your identity will never change.
  • Its usage is fast, consistent and dependable.
  • You can make sure that it’s you who has unlocked is through unique fingerprints.
  • Online transactions have become more suitable because of fingerprint authentication.

so let’s start building the app

  • Create a new Project.
  • Select File and choose New Project to create a new project in Android Studio and change the version of SDK to Android 6.0 (API123).
  • Next step: Now you have to add USE_FINGERPRINT permission to AndroidManifest.xml file because you are working with fingerprint authentication.

Next step go to and write below codes. This class contains the following methods and functions like OnCreate() method that includes activity_main.xmlgenerateKey() function produces an encryption key that can be stored safely on the device.cipherInit() function to initialize the cipher to create the encrypted FingerprintManager. CryptoObject instance checks before starting the authentication process.

Write the code given below to create a layout xml file named  to activity_main.xml

Right-click on your Project, NewActivityBasic Activity to create an Activity and update the following files as shown below.

  • Add these code to activity_second.xml

  •  Creating Fingerprint Authentication Handler Class.
  •  Create the Hander class by naming it, that extends FingerprintManager.AuthenticationCallback and contains some extra modules. Replace the code given below with the one in file.

  • To update the file open colors.xml file which you could find under resvalues

  • Then update the file by opening strings.xml file found in resvalues.

⦁Using Android Image Assets you can create the fingerprint icon. For this, right click the drawable folder then create a NewImage Asset named it the fingerprint.

Read also: How to add Push notification in Android using Firebase (cloud messaging)

Testing the Project

  • Testing on a physical device
  • Your project is almost complete now you have to debug the App on a physical Android device by putting your fingertip on the fingerprint scanner. The user will get to the Home Activity as
  • shown below if Fingerprint authentication is successful.
  • Android Fingerprint Authentication.
  • Testing on an Emulator

To test an App on an emulator follows the following steps:

  • If you have not installed Android SDK Tools Revision 24.3 then install it.
  • in emulator Go to SettingsSecurityFingerprint and follow the enrollment instructions to Enroll a new fingerprint in the emulator.
  • To emulate the fingerprint touch events use an emulator with the following command given below. This command can be used in fingerprint touch events on the lock screen or in the App.

adb -e emu finger touch <finger_id>

I hope you learned how to add Fingerprint Authentication in Android.



Leave A Reply

Your email address will not be published.