B4A Library Fingerprint Authentication

Status
Not open for further replies.
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

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

DonManfred

Expert
Licensed User
Longtime User
As Erel already answered. The Android Fingerprint Api does NOT provide any Key or something.
If the fingerprint is known by the system you get an positive answer. Negative if the fingerprint is not registered.
That´s it.

You know the fingerprint is known by the device or not. It does not give any informations about the finderprint-signature or whatever.

There is nothing we can do
 
Last edited:

Christian Gonzales

Member
Licensed User
As Erel already answered. The Android Fingerprint Api does NOT provide any Key or something.
If the fingerprint is known by the system you get an positive answer. Negative if the fingerprint is not registered.
That´s it.

You know the fingerprint is known by the device or not. It does not give any informations about the finderprint-signature or whatever.

There is nothing we can do


However as I point out in the link those options is possible
 

Rokko

Member
Licensed User
Hi Erel,

I need a litlle advice with the FingerprintManager.

If fingerprint.Authenticate is started once it's running until "success" or if there are enough "fails" and then it cancels the Authentication method. Now my question: Is there any possibility to stop fingerprint.Authenticate by code? Something like StopService(...)?

Thanks a lot.

Regards, Rokko
 

EDC

New Member
Licensed User
Hi Erel

I just start since some Week on B4A for specific application. Hard to go forward but with yours many replys all over this forum it is more or less easier to go forward.
I tried your code but I have error as
Error occurred on line: 24 (Fingerprint)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean DCipay.soft.fingerprintmanager._gethardwaredetected(DCipay.soft.fingerprintmanager)' on a null object reference
at DCipay.soft.fingerprint._activity_create(fingerprint.java:394)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at DCipay.soft.fingerprint.afterFirstLayout(fingerprint.java:104)
at DCipay.soft.fingerprint.access$000(fingerprint.java:17)
at DCipay.soft.fingerprint$WaitForLayout.run(fingerprint.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
** Activity (fingerprint) Resume **

Can you please help me ?
Thanks
 

EDC

New Member
Licensed User
Enclosed the part of my projet for fingerprint
 

Attachments

  • testfingerprint.zip
    10.8 KB · Views: 526

EDC

New Member
Licensed User
Maybe an error but with also error

** Activity (fingerprint) Create, isFirst = true **
Error occurred on line: 18 (Fingerprint)
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String DCipay.soft.fingerprintmanager._initialize(DCipay.soft.fingerprintmanager, anywheresoftware.b4a.BA, java.lang.Object, java.lang.String)' on a null object reference
at DCipay.soft.fingerprint._activity_create(fingerprint.java:381)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at DCipay.soft.fingerprint.afterFirstLayout(fingerprint.java:104)
at DCipay.soft.fingerprint.access$000(fingerprint.java:17)
at DCipay.soft.fingerprint$WaitForLayout.run(fingerprint.java:82)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
** Activity (fingerprint) Resume **
 

EDC

New Member
Licensed User
OK Erel I modify the code and the layout and working fine now.
I would also like to keep datas from external datacenter . Can you please suggest the best way to do it the best forum to follow with the most important security level and faster response. Thanks for all the things you do on this website.
Also another point I work on a complete and special application for the next future. can you recommend a company or an expert who can create an complete application within B4X (needs B4A, B4I and B4J for a small box also need with my project)
 
Status
Not open for further replies.
Top