I have implemented this code to change the language of the App and it works correctly in the emulator with API 23, 24, 25, 26, 27 and 28 and in the real device also when installed in "Active Build Variant" mode in "debug" state
Info: Android N change language programmatically
But when I upload the app to Google Play Store in "Active Build Variant" mode in "release" state the language change does not work on the real device
That could be happening ? I don't know what to do with this problem anymore. I appreciate if you can help me. Thanks
My method static ContextWrapper, class Config:
public static ContextWrapper changeLang(Context context, String lang_code){
Locale sysLocale;
Resources rs = context.getResources();
Configuration config = rs.getConfiguration();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
sysLocale = config.getLocales().get(0);
} else {
sysLocale = config.locale;
}
if ( !lang_code.equals("") ) {
Locale locale = new Locale(lang_code);
Locale.setDefault(locale);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
config.setLocale(locale);
} else {
config.locale = locale;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
context = context.createConfigurationContext(config);
} else {
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
}
}
return new ContextWrapper(context);
}
My Activity code
@Override
protected void attachBaseContext(Context newBase) {
pref = PreferenceManager.getDefaultSharedPreferences( newBase );
String lang_code = pref.getString("LANG_APP","");
Context context = Config.changeLang(newBase, lang_code);
super.attachBaseContext(context);
}
That could be happening ? I don't know what to do with this problem anymore. I appreciate if you can help me. Thanks