Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Add Android biometric authentication seems really difficult...
QtWS25 Last Chance

Add Android biometric authentication seems really difficult...

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 2 Posters 622 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • FalsinSoftF Offline
    FalsinSoftF Offline
    FalsinSoft
    wrote on last edited by FalsinSoft
    #1

    Hi all

    Maybe there is a problem about how Qt work on Android. I would to add the biometric authentication to my app by using java code as explained here. However the use of BiometricPrompt android class require to have a androidx.fragment.app.Fragment and a corresponding FragmentActivity or AppCompatActivity. However the base android Qt java class derive from standard Activity (returned by QNativeInterface::QAndroidApplication::context()) and, as consequence, is not possible to use BiometricPrompt and a lot of other API call working with Fragment. I'm thinking for a solution to create a FragmentActivity over the QML android window but is it the correct way to do or someone have a better and more simpler suggestion to follow?
    Thank you

    1 Reply Last reply
    0
    • NaLogoN Offline
      NaLogoN Offline
      NaLogo
      wrote on last edited by NaLogo
      #2

      Hi there!

      It is indeed a little tricky, but - you don't actually need the Fragment-based component. I have a solution for this to utilize biometrics in the most basic way (merely as an "authenticated? yes/no" method, no payload) by returning the result as a string to a JNI method.

      You can construct and display the Biometric prompt by using the packages

      androidx.biometric.BiometricManager
      

      and

      android.hardware.biometrics.BiometricPrompt
      

      The second one is the important one here. It's the standard, non-AndroidX package for the prompt. That one does not require a Fragment.

      Then, you construct your BiometricManager from the app context. (Remember to set a theme via style ID for the context first!)
      The BiometricManager is useful for checking whether the device even offers biometrics or whether they are set up in the first place.
      Afterwards, you can construct a BiometricPrompt using BiometricPrompt.Builder() by passing the context to it.

      Finally, you call authenticate() on your BiometricPrompt, which will trigger the display of the prompt. By using callbacks, the result can be transmitted to the app using a JNI method.

      The examples you can find in the official Android documentation for these packages should give enough info to implement this. But if they don't, let me know here and I'll gladly try to help further.

      1 Reply Last reply
      1
      • FalsinSoftF Offline
        FalsinSoftF Offline
        FalsinSoft
        wrote on last edited by
        #3

        I really thank you for the suggestion. I didn't know a (legacy?) version of BiometricPrompt existed. I'll try to use this package and report here the result.

        1 Reply Last reply
        2
        • FalsinSoftF Offline
          FalsinSoftF Offline
          FalsinSoft
          wrote on last edited by
          #4

          Thanks to your suggestion I finally was able to add the biometric authentication to my library. In case you will need it feel free to use. You can find it here:

          https://github.com/FalsinSoft/QtAndroidTools

          1 Reply Last reply
          2
          • FalsinSoftF FalsinSoft has marked this topic as solved on
          • NaLogoN Offline
            NaLogoN Offline
            NaLogo
            wrote on last edited by
            #5

            Awesome, thank you for sharing!

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved