How do I get the user’s current Locale in Android?
I can get the default one, but this may not be the current one correct?
Basically I want the two letter language code from the current locale. Not the default one. There is no Locale.current()
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The default
Localeis constructed statically at runtime for your application process from the system property settings, so it will represent theLocaleselected on that device when the application was launched. Typically, this is fine, but it does mean that if the user changes theirLocalein settings after your application process is running, the value ofgetDefaultLocale()probably will not be immediately updated.If you need to trap events like this for some reason in your application, you might instead try obtaining the
Localeavailable from the resourceConfigurationobject, i.e.You may find that this value is updated more quickly after a settings change if that is necessary for your application.
Update for > API 24 from the comments