问题描述
我改变基于用户选择的应用程序的语言环境。独立设备的语言环境。
I am changing the application locale based on user choice. Independent of device locale.
使用
public void setDefaultLocale(Context context, String locale) {
Locale appLoc = new Locale(locale);
Locale.setDefault(appLoc);
Configuration appConfig = new Configuration();
appConfig.locale = appLoc;
context.getResources().updateConfiguration(appConfig,
context.getResources().getDisplayMetrics());
}
不过,我想知道这将是该设备的语言环境也。
But I want to know what will be the device locale also.
当我试图让这个我总是得到我所设置的应用程序的语言环境。
When I am trying to get this I always getting the locale which I have set to application.
例如:applictaion是 英文的和设备在 中国的。我总是得到的的英语的
ex: applictaion is in ENGLISH and device is in CHINESE.I am always getting english.
有关使用获得的语言环境,
for getting locale using,
选项1。
String locale = context.getResources().getConfiguration().locale.getCountry();
选项2。
String local_country = ((Activity) context).getBaseContext().getResources().getConfiguration().locale.getCountry();
任何帮助将是非常美联社preciated!
Any help will be highly appreciated!!!
推荐答案
我完全不知道该如何移动,这是不同的设备:
I am absolutely unsure how portable this is to different devices:
try {
Process exec = Runtime.getRuntime().exec(new String[]{"getprop", "persist.sys.language"});
String locale = new BufferedReader(new InputStreamReader(exec.getInputStream())).readLine();
exec.destroy();
Log.e("", "Device locale: "+locale);
} catch (IOException e) {
e.printStackTrace();
}
如果你想在全国部分:persist.sys.country
And if you want the country part: persist.sys.country
这篇关于如何改变应用程序的语言环境后获得设备的语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!