完成!!!
我與其他用戶分享我的代碼!它需要英文語言環境下當前活動應用程序的名稱:
public static void setLocale(Locale locale, String packageName)
{
try
{
Context myAppContext = App.context();
Context otherAppContext = myAppContext.createPackageContext(packageName, myAppContext.CONTEXT_IGNORE_SECURITY);
Locale.setDefault(locale);
Configuration appConfig = new Configuration();
appConfig.locale = locale;
otherAppContext.getResources().updateConfiguration(appConfig, App.context().getResources().getDisplayMetrics());
}
catch(Throwable t){History.Error(t);}
}
public static String getActive()
{
try
{
PackageManager pm = App.context().getPackageManager();
ActivityManager am = (ActivityManager) App.context().getSystemService(App.context().ACTIVITY_SERVICE);
RunningTaskInfo taskInfo = am.getRunningTasks(1).get(0); // The first in the list of RunningTasks is always the foreground task.
String packageName = taskInfo.topActivity.getPackageName();
setLocale(new Locale("en-US"), packageName);
PackageInfo appInfo = pm.getPackageInfo(packageName, 0);
String label = appInfo.applicationInfo.loadLabel(pm).toString();
App.Toast(label);
return label;
}
catch (Throwable t){History.Error(t);}
return "???";
}
來源
2013-11-04 11:15:24
XXX
這不是系統範圍的設置嗎? – dacwe