Sitemap
ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.

BiometricManager.Strings-Android12

3 min readApr 15, 2022

--

BiometricManager Strings Android12

Android 12 provides new APIs to improve our applications’ biometric authentication user experience.

BiometricManager.Strings class added to the BiometricManager which has 3 methods that expose the String values that we can use for prompt message, button label, and settings label.

Methods

  1. getButtonLabel(): returns a localized string that can be used as the text of a view that invokes BiometricPrompt(e.g button’s text)
Press enter or click to view image in full size
Button’s text
  • getPromptMessage(): returns a localized string that can be shown while the user is authenticating with BiometricPrompt.
  • getSettingName(): returns a localized string that can be shown as the text for an app setting that enables authentication with BiometricPrompt(e.g switch’s text).
Press enter or click to view image in full size
Setting label

All the methods may return null if none of the requested authenticator types are available.

Returned strings depend on which authentication methods are available on the device:

Messages based on the authentication modes

Implementation 🧑‍💻

  • Add biometric permission in AndroidManifest.xml
AndroidManifest.xml
  • Add Androidx’s biometric library dependency inbuild.gradle(app)
build.gradle (app level)
  • Finally, add the following code in Activity/Fragment
https://gist.github.com/navczydev/a5ec7064373a036f6e2bc13941caef19
  • We need to have an instance of BiometricManager to check if biometrics is available or not (line3 in the above gist file)
  • After getting the true result from canAuthenticate() method we can move forward and create an instance of android.hardware.biometrics.BiometricManager
  • Access the getStrings() method and access all the methods to get the localized string values.

References

https://developer.android.com/reference/android/hardware/biometrics/BiometricManager.Strings

Get Nav Singh’s stories in your inbox

Join Medium for free to get updates from this writer.

https://developer.android.com/reference/android/hardware/biometrics/BiometricManager

Fingerprint Icon by Jemis Mali

Face id icon

😊😊 👏👏👏👏 HAPPY CODING 👏👏👏👏 😊😊

Press enter or click to view image in full size
https://www.buymeacoffee.com/navczydev

--

--

Nav Singh
Nav Singh

Written by Nav Singh

Google Developer Expert for Android | Mobile Software Engineer at Manulife | Organizer at GDG Montreal

ProAndroidDev
ProAndroidDev

Published in ProAndroidDev

The latest posts from Android Professionals and Google Developer Experts.