安装我的Android程序后,我检查设备区域设置:
String deviceLocale=Locale.getDefault().getLanguage();
Run Code Online (Sandbox Code Playgroud)
如果deviceLocale在我支持的语言(英语,法语,德语)内,我不会更改语言环境.
但是比如说如果我不支持设备的语言:例如西班牙语.
我将当前的语言环境设置为英语,因为大多数人可以部分理解英语.
Locale locale = new Locale("en");
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
pContext.getResources().updateConfiguration(config, null);
Run Code Online (Sandbox Code Playgroud)
但在那之后,在其他方法中,当我检查设备的语言环境时,如下所示:
String deviceLocale=Locale.getDefault().getLanguage();
Run Code Online (Sandbox Code Playgroud)
我得到的结果是"英语".但设备的区域设置是西班牙语.
getLanguage()是否提供当前应用的区域设置?
如何获取设备的区域设置?
编辑:在应用程序的首次运行中,它是一个保存设备区域设置的选项.但是如果用户在保存后更改设备区域设置,则无法知道设备的新区域设置.我只能知道我在app install中保存的语言环境.