I need to get the device Locale
on android studio, but apparently the code below only works on api level 24+; How can i achieve the same result as this line of code in lower level apis?
getResources().getConfiguration().getLocales().get(0);
I need to get the device Locale
on android studio, but apparently the code below only works on api level 24+; How can i achieve the same result as this line of code in lower level apis?
getResources().getConfiguration().getLocales().get(0);
well according to google docs the command public Locale locale
has deprecated in API 24 and you are allowed to use getLocales()
and setLocales(android.os.LocaleList)
in API levels above 24. so you should yoconfiguration.locale
instead in lower APIs.
@Override
public void applyOverrideConfiguration(Configuration overrideConfiguration) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1) {
// update overrideConfiguration with your locale
setLocale(overrideConfiguration) // you need to implement this
}
super.applyOverrideConfiguration(overrideConfiguration);
}
also check this out, it says it all:
For lower lavel api, you can use
Locale current = getResources().getConfiguration().locale;