【问题标题】:Locale.getDefault() is outdated on some Android devicesLocale.getDefault() 在某些 Android 设备上已过时
【发布时间】:2018-01-15 07:37:14
【问题描述】:

我的应用中有一个广播接收器,当设备的区域设置更改时会调用它。我的应用程序在一些设备上存在错误,特别是 Nexus 5x 和 Galaxy S8+(很可能还有其他设备),其中 Locale.getDefault() 返回过时/以前的值。新语言的本地化字符串正确显示,但在应用程序内部,我们的语言环境已过时。有什么想法吗?

例如:

1) Device is in English -> App locale tells us we are in English.

2) Background the app and change the device language to German

3) App receives the locale changed broadcast event, Locale.getDefault() returns English instead of German

我看到许多设备在此处返回德语,但不是所有设备。

【问题讨论】:

    标签: android locale


    【解决方案1】:

    another answer 中所述,默认语言环境是静态定义的at the time the application is created。尝试直接从资源中检索语言环境。

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
        return getResources().getConfiguration().getLocales().get(0);
    } else{
        return getResources().getConfiguration().locale;
    }
    

    【讨论】:

    • 不幸的是,这些方法中的每一个都返回相同的陈旧值。
    猜你喜欢
    • 2014-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多