Exploring Android 12: BiometricPrompt Localizable Strings
Essentially, developers will be able to access three new methods to get localized strings related to biometric prompt:
getLabelButton(): Gets button label that invokes the biometric prompt.
getPromptMessage(): Gets message shown while the user is authenticating with biometric prompt.
getSettingName(): Gets title of an app setting that enables authentication with biometric prompt.
You can use these strings for your UI elements instead of creating it yourself in
In this article, we will create a simple application that demonstrates this new methods. The final result can be shown in the image below:
Where’s the Source Code?
android-12-samples/biometricprompt-localizable-strings at master · hanmajid/android-12-samples
Sample projects for Android 12. Contribute to hanmajid/android-12-samples development by creating an account on GitHub.
Step by Step Explanation
Follow the steps provided below to create this application.
1. Open Android Studio. Create new project with “Empty Activity” option.
2. First, we need to add Biometric library to our application. Open
app/build.gradle file and add this dependency:
3. Next, we will update our layout,
activity_main.xml file. The image below shows how the layout will look like. It will contain TextViews for displaying the localized button label, prompt message, and setting name.
To make this layout, copy-paste the code snippet below:
4. Lastly, we need to update our
MainActivity.kt file. Go ahead and copy-paste the code snippet below. There are some important things to notice here. First, the usage of
BiometricManager.getStrings() for retrieving the localized strings. You need to pass authenticators to this method based on the types of authentication that you want to use in your app. Different authenticators will result in different localized strings.
Another thing to notice here is obviously the usage of
getSettingName() methods to retrieve the localized strings.
5. That’s it! Now run your app and see the localized strings for yourself. Change your device’s language in the Settings to see the different strings like this:
As always, thanks for reading!
Want to learn more about Android 12?
Check out all of our articles from “Exploring Android 12” series here: