Search code examples
androidtranslationandroid-biometric-prompt

BiometricPrompt hints are not localized


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
        }

    }
}

Solution

  • 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.