B4A Library Fingerprint Authentication

Status
Not open for further replies.
Newer class: https://www.b4x.com/android/forum/threads/biometricmanager-biometric-authentication.111256/



This class uses inline Java to access the fingerprint API introduced in Android 6.
It will only work on Android 6+ devices.

With this class it is simple to authenticate the user based on his fingerprint. Note that this is a different kind of authentication compared to FirebaseAuth. It is a local authentication that is useful for preventing others from accessing the app.

Usage code:
B4X:
Sub Process_Globals
   Private fingerprint As FingerprintManager
End Sub

Sub Globals
   Private btnAuthenticate As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     fingerprint.Initialize (Me, "auth")
   End If
   Activity.LoadLayout("1")
   If fingerprint.HardwareDetected = False Then
     ToastMessageShow("Fingerprint sensor not detected.", True)
   Else if fingerprint.HasEnrolledFingerprints = False Then
     ToastMessageShow("No fingerprints were enrolled.", False)
   Else
     btnAuthenticate.Enabled = True
   End If
End Sub

Sub btnAuthenticate_Click
   fingerprint.Authenticate
   ToastMessageShow("Scanning...", False)
End Sub

Sub Auth_Complete (Success As Boolean, ErrorMessage As String)
   If Success Then
     ToastMessageShow("You have been authenticated!!!", True)
   Else
     ToastMessageShow($"Error: ${ErrorMessage}"$, True)
     Log(ErrorMessage)
   End If
End Sub

Manifest editor:
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="23" android:targetSdkVersion="23"/>
<supports-screens android:largeScreens="true"
  android:normalScreens="true"
  android:smallScreens="true"
  android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddPermission(android.permission.USE_FINGERPRINT)

At least one fingerprint should be enrolled (under Settings - Security). Note that there must be a screen lock set.
 

Attachments

  • FingerprintManager.bas
    2.5 KB · Views: 1,250
Last edited:

Hamied Abou Hulaikah

Well-Known Member
Licensed User
Longtime User
I got this error:

B4X:
B4A version: 6.30
Parsing code.    (0.01s)
Compiling code.    (0.06s)
   
ObfuscatorMap.txt file created in Objects folder.
Compiling layouts code.    (0.07s)
Organizing libraries.    (0.01s)
Generating R file.    (0.13s)
Compiling generated Java code.    Error
javac 1.7.0_40
src\b4a\example\fingerprintmanager.java:3: error: package android.hardware.fingerprint does not exist
import android.hardware.fingerprint.*;
^
Note: src\b4a\example\starter.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
 

alexhi

Member
Licensed User
Longtime User
I put one finger. If I bring it OK. If I put another finger application close. Why?
 

alexhi

Member
Licensed User
Longtime User
No errors

And I no see
ToastMessageShow($"Error: ${ErrorMessage}"$, True)
 

bluedude

Well-Known Member
Licensed User
Longtime User
Does not work on a Samsung S7. The Auth_Complete event is never triggered.
 

bluedude

Well-Known Member
Licensed User
Longtime User
No fail or whatsoever. It starts without a fail and it scans but the event is not triggered at all. I compiled with API 24 and I also use fingerprint unlock etc. So there are multiple fingerprint profiles.
 

Geezer

Active Member
Licensed User
Longtime User
I have a Galaxy S5 and the fingerprint reader is not detected. Am I missing a setting on my phone ?
 

alexhi

Member
Licensed User
Longtime User
Hi Erel! Its work OK. I tested noname phone K6 (china) Android 6. Can I have number fingerprint in this class?
 

alexhi

Member
Licensed User
Longtime User
Snx DonManfred!
Sorry for my bad English.
May I ask what kind of put a finger? (From registered)?
 

microbox

Active Member
Licensed User
Longtime User
I was wondering if it can capture the values from finger after scan so that I can use it for my own purpose. Is this possible?
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…