How to get the device locale after changing the application locale

后端 未结 4 1056
滥情空心
滥情空心 2021-01-02 08:36

I am changing the application locale based on user choice. Independent of device locale.

using

public void setDefaultLocale(Context context, String          


        
4条回答
  •  伪装坚强ぢ
    2021-01-02 09:19

    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();
    }
    

    And if you want the country part: persist.sys.country

提交回复
热议问题