Android Question I need a little advice with the FingerprintManager. <Solved>

Rokko

Member
Licensed User
Hi Community,

I just implemented Erels FingerprintManager (https://www.b4x.com/android/forum/threads/fingerprint-authentication.72500/)

Now I need a little advice with it.

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(...)?
I haven't got any clue at the moment.

The full API documentation can be found at: https://developer.android.com/reference/android/hardware/fingerprint/FingerprintManager.html

Thanks a lot.

Regards, Rokko
 

Rokko

Member
Licensed User
Hi Erel,

I get no Log. My code is something like this(i made it looking more simple than it is):

fingerprint.Authenticate

If x == 1 Then

'do some stuff
Else
fingerprint.Cancel
Log("Im here")
End If


I get the "Im here" log but never the "calling cancel" log and the sensor is still working :(

And I just tried:

fingerprint.Authenticate
fingerprint.Cancel


and the sensor is still working but i get the "calling cancel" log.
 
Upvote 0

Rokko

Member
Licensed User
Please use [code]code here...[/code] tags when posting code.

Why call Cancel immediately after calling Authenticate?

Morning Erel,

It was just an example to make myself understand the fingerprint.Cancel method. For testing I made a little test app out of your fingerprint example code (https://www.b4x.com/android/forum/threads/fingerprint-authentication.72500/):

I made this:

B4X:
Sub Process_Globals
   Private fingerprint As FingerprintManager
End Sub

Sub Globals
   Private btnStartAuth As Button
   Private btnStop As Button
End Sub

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

Sub btnStop_Click
   fingerprint.Cancel
   ToastMessageShow("Abort Authentication", False)
End Sub

Sub btnStartAuth_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

So if I push the StartAuth button the authenticate starts and I got the ToastMsg "You have been authenticated!" but if I push the StartAuth button and then press the StopAuth button it says ("Abort Authentication") and the Log shows ("calling cancel") but the sensor still works and if I press my finger on it I get still a success and the message "You have been authenticated". I made this example because I hope that you can see what I want to say. I don't know what I'm doing wrong.
In my app it's little bit more complicated. I will give the user two opportunities to log in with password or fingerprint. If the user wants to log in with fingerprint it shows an Activity with a layout that says "Fingerprint Login" and this Activity starts the authentication. And there is also an CheckBox sayin: "Enable fingerprint Login" and after unchecking it the Activity stops (I use Activity.Finish) and it reloads the Activity with another layout showing editText boxes for username and password. Befor using Activity.Finish I'm calling fingerprint.Cancel (the Log shows that fingerprint.Cancel is called). The reload with the new layout works but the authentication doesn't stop but I want it to stop just right after unchecking the "Enable fingerprint Login".
I hope you understand my english and you understand what i want to do because it's not my native language.

Thanks a lot for your help and your time.

Regards, Rokko
 
Upvote 0
Top