Android — Integrating Fingerprint authentication in your apps

Musthaq Ahamad
Jul 23, 2018 · 3 min read
Image for post
Image for post

Fingerprint authentication has been a huge leap towards a better user experience in smartphones. Having this golden feature in your user’s phone and trying to integrate this feature in your applications to increase security and the bonus of better user experience is worth a shot. Let’s see how we can quickly integrate a simple FingerPrint authentication into an android app.

While integrating Fingerprint auth in our applications, we need to take care of quite a lot of things concerning the hardware of the device our users are using. We know that only devices running android Marshmallow and above have support for Fingerprint scanners. Additionally to use the Android’s built-in Fingerprint features the user needs to have enabled fingerprint security in the device and have at least one fingerprint registered in the device. Let’s keep these points in mind and we need to check these things before dispatching a listener for fingerprint authentication.
So, Let’s get started!

Permission for Fingerprint use

We need our application’s manifest file to describe that our application needs permission to use Fingerprint. Let’s add the following line inside the manifest tag inside the AndroidManifest.xml file.

Checking Fingerprint availability

As I mentioned above, we need to verify that the user runs appropriate Android version, the device has the necessary hardware for the Fingerprint scanner and the user has at least one fingerprint already registered in the device.
Write down the following method in your activity’s class or create a separate java file and drop this method in there.

Creating a Fingerprint Helper class

Next, we need to create a helper class by extending the FingerprintManager.AuthenticationCallback and we'll create an interface inside this class for the authentication listner.

Additionally, we need to create methods to start authentication, cancel the listner and implement the methods in the AuthenticationCallback to interact with our listner. Now our FilgerprintHelper will look like this.

Implementing the listener in Activity

Once we have created the and the FingerprintHelperListener inside it, we can implement the listner in our Activity.

We need to create variables of FingerprintManager and FingeprintHelper in our activity.

Next, we’ll check for the Fingerprint settings using the function checkFingerprintSettings we discussed above in this post and start listneing when the Activity starts and cancel the listening when the activity is paused ie. app went to background. So add the following line of code inside your activity by overriding the onResume() and the onPause() method.

That’s it! You’re ready to roll with the new feature on your app. Now your Activity class should look something like this.

Originally published at zocada.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store