I have a problem to change the language to Android 6.0.1, on new Android versions change language works well, but on 6.0.1 set up default string regardless of the language the device is set up. The emulator works, but when I install the apk on Samsung J5, which does work on Android 6.0.1 change language dont work. Is there any solution to my problem? Thank you.
private void setLocale(String lang) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Locale locale = new Locale(lang);
Locale.setDefault(locale);
Configuration config =
getBaseContext().getResources().getConfiguration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
} else {
Resources resources = getBaseContext().getResources();
Configuration configuration = resources.getConfiguration();
configuration.setLocale(new Locale(lang));
getBaseContext().getApplicationContext().createConfigurationContext(configuration);
}
// shared pref.
SharedPreferences.Editor editor = getSharedPreferences("Settings", MODE_PRIVATE).edit();
editor.putString("My_Lang", lang);
editor.apply();
}