B4J Tutorial [Web] Beginning Telegram Mini Apps - BiometricManager

Hi Fam

Demo (Open the bot from your Mobile Device > Sign In (use any details) > Hamburger > Biometrics > Follow the button sequence. When you click Authenticate, it will show the biometrics

Source Code

With the Biometric Manager, one is able to authenticate user access to the app using biometric.

WhatsApp Image 2024-07-26 at 01.59.29.jpeg


WhatsApp Image 2024-07-26 at 13.00.30.jpeg




NB: The fingerprint display is "blacked out" by device due to security policy.



Related Content


 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
When one opens the page, the Init method is called. This calls the _ready sub routine.

B4X:
'called by init
Sub Biometric_Ready
    app.ShowToastSuccess("Biometrics is ready")
    banano.Await(biometrics_ReadValues)
End Sub

One can then requestAccess and authenticate to show the fingerprint / biometric prompt

B4X:
Sub btninit_click (e As BANanoEvent)
    e.PreventDefault
    'check the status
    Dim bIsInit As Boolean = BM.IsInited
    If bIsInit = False Then
        'initialize the biometrics
        BM.Init(Me)
    Else
        app.ShowToastSuccess("Biometrics already init!")
    End If
End Sub
'
Sub btnrequestaccess_click (e As BANanoEvent)
    e.PreventDefault
    BM.RequestAccess(Me, "The bot uses biometrics for testing purposes")
End Sub
'
'called by request access
Sub Biometric_RequestAccess (Granted As Boolean)
    chkisaccessrequested.Checked = BM.IsAccessRequested
    chkisaccessgranted.Checked = BM.IsAccessGranted
    Select Case Granted
    Case True
        app.ShowToastSuccess("Biometrics access granted")
    Case False    
        app.ShowToastError("Biometrics access NOT granted")
    End Select
End Sub


Sub btnauthenticate_click (e As BANanoEvent)
    e.PreventDefault
    BM.Authenticate(Me, "The bot uses biometrics for testing purposes")
End Sub

Sub Biometric_Authenticate (Success As Boolean, Token As String)
    Select Case Success
    Case False
        BM.Token = ""
        txttoken.Value = ""
    Case Else    
        BM.Token = Token        
        txttoken.Value = BM.Token
    End Select
End Sub

Sub btnupdatetoken_click (e As BANanoEvent)
    e.PreventDefault
End Sub
'
Sub btnopensettings_click (e As BANanoEvent)
    e.PreventDefault
    BM.OpenSettings
End Sub
 
Top