How to get the device locale after changing the application locale

后端 未结 4 1082
滥情空心
滥情空心 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:23

    for those whom are using Daniel Fekete 's solution which is :

    Process exec = Runtime.getRuntime().exec(new String[]{"getprop", "persist.sys.language"});
    String locale = new BufferedReader(new InputStreamReader(exec.getInputStream())).readLine();
    exec.destroy();
    

    Be aware of that locale might be EMPTY on latest Android Api(+21)! instead of using persist.sys.language use persist.sys.locale

    exec = Runtime.getRuntime().exec(new String[]{"getprop", "persist.sys.locale"});
    locale = new BufferedReader(new InputStreamReader(exec.getInputStream())).readLine();
    exec.destroy();
    

提交回复
热议问题