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
- getButtonLabel(): returns a localized string that can be used as the
textof a view that invokesBiometricPrompt(e.g 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
textfor an app setting that enables authentication withBiometricPrompt(e.g switch’s text).
All the
methodsmay return null if none of the requested authenticator types are available.
Returned strings depend on which authentication methods are available on the device:
Implementation 🧑💻
- Add biometric permission in
AndroidManifest.xml
AndroidManifest.xml- Add Androidx’s biometric library dependency in
build.gradle(app)
- Finally, add the following code in Activity/Fragment
- We need to have an instance of
BiometricManagerto check if biometrics is available or not (line3 in the above gist file) - After getting the
trueresult fromcanAuthenticate()method we can move forward and create an instance ofandroid.hardware.biometrics.BiometricManager - Access the
getStrings()method and access all the methods to get thelocalized stringvalues.
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










