2017-01-03 73 views
0

任何人都知道可以通過編程方式爲設備設置系統語言嗎? 我瞭解的問題,我們不能使用在設備中設置系統語言環境

`android.permission.CHANGE_CONFIGURATION` 

我測試了它與反映的方法(谷歌在Android 5.0以上版本改變了它)。而它的工作,只有當我們授予權限與亞行(其不正確的方法)

adb grant mypackage android.permission.CHANGE_CONFIGURATION 

我的應用程序有一個管理員權限,我希望也許當我的應用程序有另一種方式管理應用程序,我可以programmaticaly更改設備的語言環境?

+0

http://stackoverflow.com/questions/40942535/using-locale-to-force-android-to-use-a-specific-strings-xml-file-for-a-non-suppo/40986303#40986303 – Onik

回答

0

該方法完成大部分工作。相應編輯

private static boolean updateResources(Context context, String language) { 
     Locale locale = new Locale(language); 
     Locale.setDefault(locale); 

     Resources resources = context.getResources(); 

     Configuration configuration = resources.getConfiguration(); 
     configuration.locale = locale; 

     resources.updateConfiguration(configuration, resources.getDisplayMetrics()); 

     return true; 
    } 

它從您傳入的語言字符串中選擇一個新的語言環境,然後更新應用程序的資源文件。

+0

此方法僅適用於APP,我需要系統語言。 – Peter