Reputation: 71
I added support per app language to my app, the android 13 feature, now it is both English and Russian. I can change the app language from settings and no need to change the device language. Now for analytics purposes, I need to know the app language and the device language. But if my device is in English and the app is in Russian, I always receive Russian -
Resources.getSystem().configuration.locales.get(0).language - ru
context.resources.configuration.locales[0].language - ru
Locale.getDefault().language - ru
I expect to receive en from
Resources.getSystem().configuration.locales.get(0).language
and ru from
context.resources.configuration.locales[0].language
I will be glad for any help
Upvotes: 7
Views: 2015
Reputation: 176
I've been working with these:
AppCompatDelegate.getApplicationLocales() // app locales
LocaleManagerCompat.getSystemLocales(Context) // system locales
getApplicationLocales()
may return an empty array []
if there is no app-level setting. In that case, the system locale is being used.
I also use AppCompatDelegate.setApplicationLocales(LocaleListCompat)
for consistency.
I'm not sure if there are non-Compat classes available for targeting only API 33, but this is currently working for me down to API 27.
As mentioned in another answer, you'll need to import androidx.appcompat:appcompat:1.6.0-beta01
- see first line here.
Upvotes: 7
Reputation: 41
The system locale list is available from LocaleManagerCompat.getSystemLocales(Context)
in androidx.core:core:1.9.0-beta01
or later.
Upvotes: 4