Android Fingerprint Authentication - Androhub

Fingerprint banner

Android Fingerprint Authentication

Android fingerprint authentication uses smartphone touch sensor to authenticate the user. Android Marshmallow has introduced a set of API that makes it easy to use the touch sensor. Before Android Marshmallow, the method to access the touch sensor was not standard.

There are several benefits of using Android fingerprint authentication:

1. Doesn’t matter how sick you are , your fingerprint still stays faultless as your identity and can never be misplaced.
2. Fast, Convenient and Reliable to use.
3. Unique fingerprints assure that it’s unlocked just by you.
4. With the help of Fingerprint authentication, online transactions become more convenient, hence your just a tap away from getting verified.

NOTE: Make sure you have at least one fingerprint is registered on the smartphone.

To authenticate users using the fingerprint sensor, you need to get an instance of the newly implemented FingerprintManager class and call the authenticate() method. However your app must be running on a compatible device which includes a fingerprint sensor. Moreover you must implement the user interface for the fingerprint authentication flow on your app, and use the standard Android fingerprint icon in your UI. Note that If you are developing multiple apps that use fingerprint authentication, each app must authenticate the user’s fingerprint separately.

Example

In this tutorial, we are going to learn how to implement Fingerprint Authentication in your application.

VIDEO DEMO

1. Create a new project in Android Studio by navigating to File ⇒ New ⇒ New Project and fill required details. By default my activity is MainActivity.java.

2. Open res ⇒ values ⇒ strings.xml and add below string values. These are some strings that we are going to use in our project.

3. Since we are going to work with Fingerprint authentication, we need to add USE_FINGERPRINT permission to AndroidManifest.xml file

4. Create the fingerprint icon with the help of Android Vector Assets. To do so, Right click on the drawable folder and Create a New ⇒ Vector Asset named ic_fingerprint_white_60dp.xml.

5. Now, open your activity_main.xml layout and place the below code.

6. Now open your MainActivity.java class and place the below code. The following class includes various steps as follows:

  • Access to Android KeyStore and Generate the Key : generateKey() function which generates an encryption key which is then stored securely on the device.

  • Create the Android Cipher : cipherInit() function that initialises the cipher that will be used to create the encrypted FingerprintManager.

  • CryptoObject instance and various other checks before initiating the authentication process which is implemented inside onCreate() method.

Full Code

7. Now create Welcome activity which will open on successful Fingerprint Authentication.

  • welcome_activity.xml

  • WelcomeActivity.java

8. Create a Fingerprint Authentication Handler class and name it FingerPrintHandler.java. The Handler class extends FingerprintManager.AuthenticationCallback and includes some additional modules so that we can receive event notification and we can know when the authentication succeeded or something went wrong.

There are some important methods to notice. First of all, the doAuth that starts the authentication process. This method has the CryptoObject, a cancellation signal and the callback listener (this class).

9. Finally you are all done. Now you can test your app in Physical Device or in Emulator. To test the app in emulator follow below steps:

  • Install Android SDK Tools Revision 24.3, if you have not done so.
  • Enroll a new fingerprint in the emulator by going to Settings ⇒ Security ⇒ Fingerprint, then follow the enrolment instructions.

Use an emulator to emulate fingerprint touch events with the following command. Use the same command to emulate fingerprint touch events on the lockscreen or in your app.

Thanks. :)

 

7 Comments

Zomby77
Friday, September 7th, 2018

Can you help me with the samsung fingerprint with help sdk pass!?
https://developer.samsung.com/galaxy/pass

Thanks in advance

Greetings from Serbia 😉

Dr. Droid
Saturday, September 8th, 2018

Hi Zomby77,

Can you tell where you are facing issue?

Thanks

Zomby77
Saturday, September 15th, 2018

I am not a developer so it’s not clear to me how to make the authentication pass … otherwise I write that I do not have a fingerprint sensor!

* An error message will be displayed if the device does not contain the fingerprint hardware.
* However if you plan to implement a default authentication method,
* you can redirect the user to a default authentication activity from here or can skip this method.
* Example:
* Intent intent = new Intent(this, YourActivity.class);
* startActivity(intent);
* finish();

It’s unclear how I can transfer authenticates to samsung pass 😀
Thank you very much for your reply

Zomby77
Saturday, September 15th, 2018

I transferred the N7 rom to S5, but the fingerprint does not work and I try to fix the sample print with the help of a simple application!I asked for help from 8-9 developers from github but no one will help me 🙁

My rom on XDA:

https://forum.xda-developers.com/galaxy-s5/development/serbiarom-oreo-v1-n7-s8-t3711237

Dr. Droid
Monday, September 17th, 2018

Hi Zomby77,

Can we have TeamViewer session so i can help you properly.

Thanks

Zomby77
Tuesday, September 18th, 2018

Yes i have 🙂

Ganesh Kumrawat
Wednesday, March 20th, 2019

sir, this code is work only if we already register our fingerprint in our phone.
please can you give me guideline to register this fingerprint in my app database then give successfully login

Post comment

Your email address will not be published. Required fields are marked *