B4A Library Fingerprint Authentication

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
Newer class: https://www.b4x.com/android/forum/threads/biometricmanager-biometric-authentication.111256/

upload_2016-10-30_16-1-30.png


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

Last edited:

HAH

Well-Known Member
Licensed 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
 

bluedude

Well-Known Member
Licensed 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
I have a Galaxy S5 and the fingerprint reader is not detected. Am I missing a setting on my phone ?
 

alexhi

Member
Licensed 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
Snx DonManfred!
Sorry for my bad English.
May I ask what kind of put a finger? (From registered)?
 

microbox

Active Member
Licensed 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.
Top