8

Issue

We are changing the locale inside the app, everything works except the hints in the fingerprint dialog. Whatever language we set, we always have english hints:

  • Touch the fingerprint sensor
  • Not recognized
  • etc...

enter image description here

Environment

  • Component used: androidx.biometric.BiometricPrompt
  • Version used: 1.0.0.0-alpha04
  • Devices/Android versions reproduced on: emulator API 28

How the locale is set:

    private fun setNewLocaleAndRestart(language: String) {
        LocaleManager(this).setNewLocale(language)

        //restarting app
        val i = Intent(this, SplashScreenActivity::class.java)
        startActivity(i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK))
        finish()
        System.exit(0)
    }

class LocaleManager(val context: Context) {

    val sharedPreferenceManager = createSharedPreferenceManager(context)

    fun setLocale(): Context = updateResources()

    fun setNewLocale(language: String): Context {
        return updateResources(language)
    }


    private fun updateResources(l: String? = null): Context {

        val language = l ?: sharedPreferenceManager.language

        if (language.isBlank()) return context

        val locale = Locale(language)

        Locale.setDefault(locale)

        val res = context.resources
        val config = Configuration(res.configuration)
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            config.setLocale(locale)
            return context.createConfigurationContext(config)
        } else @Suppress("DEPRECATION") {
            config.locale = locale
            res.updateConfiguration(config, res.displayMetrics)
            return context
        }

    }
}
Joey Phillips
  • 1,543
  • 2
  • 14
  • 22

4 Answers4

2

everything works except the hints in the fingerprint dialog

All system dialogs will use the language that the user set for the device. This includes system dialogs for biometrics.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for you answer. So with that said, does that mean that in-app language selection cannot change the system language used by those dialog ? The only way is to make the user change the language in system settings ? – Anis CAMPOS May 09 '19 at 13:27
  • @AnisCAMPOS: "does that mean that in-app language selection cannot change the system language used by those dialog ?" -- correct. At most, your `Locale` code affects your current process, nothing else. "The only way is to make the user change the language in system settings ?" -- correct. – CommonsWare May 09 '19 at 13:33
  • This is not true. If you have a date picker and set the locale, it will display in that locale. I also expected the biometrics dialog to behave the same. I have a situation where I need to display the language X in the app, wether user set english or X in the settings. I think to rely only on the system setting (exclusively) is a mistake / miss behaviour / bug / missing feature. – ramden Oct 15 '19 at 06:44
  • @ramden: "This is not true" -- yes, it is. "If you have a date picker and set the locale, it will display in that locale" -- the date picker UI is part of your process. The biometric UI is not. "I have a situation where I need to display the language X in the app, wether user set english or X in the settings" -- then do not show any UI rendered outside of your process. Among other things, you cannot request runtime permissions and you cannot use the biometrics APIs. – CommonsWare Oct 15 '19 at 10:45
  • @CommonsWare The default setting of (for example) date pickers is to respect the language setting. But you can override that by setting the locale manually. On biometric prompt you cannot. My only statement is, there should be a way to set or override these translations in the app. Otherwise the dialog is not viable. I had to use FingerprintManager for example because there at least I have control over these elements – ramden Oct 16 '19 at 07:32
  • @ramden: "But you can override that by setting the locale manually" -- Google has never fully endorsed this technique. "My only statement is" -- no, your "statement" was to call me a liar ("This is not true"). "there should be a way to set or override these translations in the app" -- malware authors agree, so they can lie to the user about what the dialog is for. "Otherwise the dialog is not viable" -- it may not be viable *for your scenario*. This goes back to what I said earlier: Google has never fully endorsed your switch-the-app-language technique. – CommonsWare Oct 16 '19 at 10:48
1

I just implemented BiometricManager androidx.biometric:biometric:1.0.1 and was able to change and localize the text for the hint and for when a wrong fingerprint was used.

You just need to define these strings in your strings.xml to override the ones on the API:

fingerprint_not_recognized to change the error message when a wrong fingerprint is used. This is defined in FingerprintHelperFragment.java

fingerprint_dialog_touch_sensor to change the hint. This is defined in FingerprintDialogFragment.java

BiometricManager_TouchSensor_Message BiometricManager_WrongFingerprintUsed_Message

Israel
  • 23
  • 4
  • 2
    It did not work for me. Do you have any code snippet to see if I am doing something wrong? – LiTTle Jan 04 '21 at 12:17
0

It was fixed in BiometricPrompt version androidx.biometric:biometric:1.0.0-alpha04. You just need to change your phone locale for the changes to reflect.

here's the commit for it if you're interested

Ahsan Zaheer
  • 646
  • 1
  • 12
  • 18
  • Hi @ahsan-zaheer, I'm not really sure to understand the "change" you are referencing. The commit in you link doesn't seem to have any relevant changes in the behavior, it's only adding some lines in the translation files. My issue is that it's not possible to change the language used by the prompt from within my app. The only way is to change the language system wide, as stated in the accepted answer – Anis CAMPOS Aug 28 '19 at 15:56
  • yes, it uses the system language. Even if you change the language within the app, the 'hints' are part of the system UI. I had the problem before the linked commit, that even if you change the system language it was still showing hints in english. – Ahsan Zaheer Aug 29 '19 at 15:23
0

I'm also experiencing this with implementation 'androidx.biometric:biometric:1.0.1@aar'. I change the system language to something else than English, but it still says "Touch the fingerprint sensor". Does anyone have a solution or an explanation to this?

It looks as if the Android biometric library already comes with support for all languages, but it doesn't seem to work. I can even see the translations in the generated merger.xml in the Android build folder.

Tested on my OnePlus 5T with Android 9/Oxygen 9.0.10.

kuhr
  • 582
  • 8
  • 18