2017-08-07 73 views
1

我的應用程序中有一個廣播接收器,當設備的區域設置更改時會被調用。我的應用程序中有幾個設備存在一個錯誤,特別是Nexus 5x和Galaxy S8 +(以及其他很可能),其中Locale.getDefault()返回陳舊/過去的值。本地化的字符串對於新語言正確顯示,但在應用程序內部,我們的區域設置已過時。有任何想法嗎?某些Android設備上的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

我看到這裏的德國返回了很多設備,但不是所有的設備。

回答

2

如在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; 
} 
+0

不幸的是,每種方法都會返回相同的陳舊值。 –

相關問題