How To Change Locale Of Another App?
I can change locale of my app using this code: public static void setLocale(Locale locale) { Locale.setDefault(locale); Configuration appConfig = new Configuration();
Solution 1:
Done!!!
I'm sharing to other users my code! It takes name of current active app in English locale:
publicstaticvoidsetLocale(Locale locale, String packageName){
try{
ContextmyAppContext= App.context();
ContextotherAppContext= myAppContext.createPackageContext(packageName, myAppContext.CONTEXT_IGNORE_SECURITY);
Locale.setDefault(locale);
ConfigurationappConfig=newConfiguration();
appConfig.locale = locale;
otherAppContext.getResources().updateConfiguration(appConfig, App.context().getResources().getDisplayMetrics());
}catch(Throwable t){
History.Error(t);
}
}
publicstatic String getActive(){
try{
PackageManagerpm= App.context().getPackageManager();
ActivityManageram= (ActivityManager) App.context().getSystemService(App.context().ACTIVITY_SERVICE);
RunningTaskInfotaskInfo= am.getRunningTasks(1).get(0); // The first in the list of RunningTasks is always the foreground task.StringpackageName= taskInfo.topActivity.getPackageName();
setLocale(newLocale("en-US"), packageName);
PackageInfoappInfo= pm.getPackageInfo(packageName, 0);
Stringlabel= appInfo.applicationInfo.loadLabel(pm).toString();
App.Toast(label);
return label;
}catch (Throwable t){
History.Error(t);
}
return"???";
}
Post a Comment for "How To Change Locale Of Another App?"