B4A Library Fingerprint Authentication

Discussion in 'Additional libraries, classes and official updates' started by Erel, Oct 30, 2016.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    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:
    Code:
    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:
    Code:
    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.
     

    Attached Files:

  2. HAH

    HAH Active Member Licensed User

    I got this error:

    Code:
    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
     
    KZero likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    You need to use a newer version of android.jar (Tools - Configure Paths). Should be 23+.
     
  4. alexhi

    alexhi Member Licensed User

    I put one finger. If I bring it OK. If I put another finger application close. Why?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Check the logs. Is there any error message?
     
  6. alexhi

    alexhi Member Licensed User

    No errors :(

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

    Erel Administrator Staff Member Licensed User

    Which device are you using? Are you able to see the unfiltered logs?
     
  8. bluedude

    bluedude Well-Known Member Licensed User

    Does not work on a Samsung S7. The Auth_Complete event is never triggered.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Do you see "fail" messages in the logs?
     
  10. DonManfred

    DonManfred Expert Licensed User

    It is working on my S7 EDGE. I can successfully Authenticate using the stored fingers...
     
    Erel likes this.
  11. bluedude

    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.
     
  12. Geezer

    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 ?
     
  13. DonManfred

    DonManfred Expert Licensed User

    Options->Security->Fingerprint

    Enable the options and define some fingers
     
  14. alexhi

    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?
     
  15. DonManfred

    DonManfred Expert Licensed User

    on a Samsung Device it is 4.
     
  16. alexhi

    alexhi Member Licensed User

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

    DonManfred Expert Licensed User

    Yes
     
  18. microbox

    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?
     
  19. DonManfred

    DonManfred Expert Licensed User

  20. alexhi

    alexhi Member Licensed User

    I use the fingerprint in my app access control system. Оpened the gate of the car (Wifi UDP + WIFI ESP8266)
    [​IMG]
     
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice