I was doing this way:
context.getResources().getConfiguration().locale
Configuration.locale
is deprecated if target is 24. So I made this change:
context.getResources().getConfiguration().getLocales().get(0)
Now it says that it's only for minSdkVersion
24, so I cannot use it because my min target is lower.
What's the right method?
Locale current = getResources(). getConfiguration(). locale; You may find that this value is updated more quickly after a settings change if that is necessary for your application.
Device locale - Android Tutorial Locale is the representation of a specific region.
When the Java virtual machine starts running on a computer, it creates an object called the default locale. This object affects the format of strings created from data. Depending on the default locale, a program creates different strings for the same number.
Check which version you're running on and fallback to the deprecated solution:
Locale locale; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { locale = context.getResources().getConfiguration().getLocales().get(0); } else { locale = context.getResources().getConfiguration().locale; }
You could use Locale.getDefault()
, which is the Java standard way of getting the current Locale
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With