How can we get the current language selected in the Android device?
-
17The majority of answers here get the language of the application. Given that you can set the default locale of the application in code, the correct answer is the answer given by Sarpe - that gives you the device's locale. – Victor Ionescu Apr 17 '15 at 08:59
-
@VictorIonescu thank you for the comment. Sarpe's answer is correct answer to fetch device's locale. Please refer it. https://stackoverflow.com/a/28498119/3762067 – Varad Mondkar Apr 04 '18 at 21:27
-
Does this answer your question? [How to identify device language from the App language in Android 13?](https://stackoverflow.com/questions/73399280/how-to-identify-device-language-from-the-app-language-in-android-13) – k4dima Mar 31 '23 at 18:34
32 Answers
I've checked the Locale methods on my Android 4.1.2 device, and the results:
Locale.getDefault().getLanguage() ---> en
Locale.getDefault().getISO3Language() ---> eng
Locale.getDefault().getCountry() ---> US
Locale.getDefault().getISO3Country() ---> USA
Locale.getDefault().getDisplayCountry() ---> United States
Locale.getDefault().getDisplayName() ---> English (United States)
Locale.getDefault().toString() ---> en_US
Locale.getDefault().getDisplayLanguage()---> English
Locale.getDefault().toLanguageTag() ---> en-US

- 278
- 2
- 11

- 33,518
- 47
- 192
- 272
-
9Thanks, nice with a list of possibilities. Could you please add "Locale.getDefault().toString()", as suggested in a comment by "Tom". – RenniePet Sep 18 '14 at 00:01
-
3there is also `Locale.getDefault().getDisplayLanguage()` which returns `"English"` – sports Jun 02 '15 at 15:39
If you want to get the selected language of your device, this might help you:
Locale.getDefault().getDisplayLanguage();
You can use Locale.getDefault().getLanguage();
to get the usual language code (e.g. "de", "en")

- 7,528
- 9
- 56
- 96

- 22,827
- 6
- 41
- 50
-
-
74getDisplayLanguage() will localise the language. If you're interested in just getting the ISO code (e.g. for if or switch statements) use 'Locale.getDefault().getISO3Language();' – nuala Jan 24 '12 at 10:25
-
14getISO3Language() returns things like "deu" for Deutschland (germany) instead of de ... – Tobias Feb 13 '12 at 21:17
-
397You can use `Locale.getDefault().getLanguage();` to get the usual language code (e.g. "de", "en"). – muscardinus May 05 '12 at 10:59
-
1And also refer this link for more variant methods http://developer.android.com/reference/java/util/Locale.html – Vins Aug 01 '12 at 12:01
-
44@DeRagan, This will not always gives you language for your device, but for your app only. For example, if I call `Locale.setDefault("ru")`, and language in system settings is set to English, then method `Locale.getDefault().getLanguage()` will return **"ru"**, but not **"en"**. Is there another method of getting real SYSTEM locale/language? I found not documented solution [here](http://stackoverflow.com/a/4683532/1048087), but is there more elegant solution? – Prizoff Sep 12 '12 at 14:29
-
52I prefer `Locale.getDefault().toString()` which gives a string that fully identifies the locale, e.g. "en_US". – Tom Jan 14 '13 at 18:11
-
@Patrick is it fair to copy paste from my answer: http://stackoverflow.com/questions/4212320/get-the-current-language-in-device/23168383#23168383 – trante Apr 16 '15 at 19:19
-
1@trante you are right it isn't fair. all i tried was helping people to get correct answers (thought that is what stackoverflow is about). sorry for not getting that it is about competing with others for points before helping people getting answers... – Patrick Boos Apr 22 '15 at 14:39
-
1really Tom's answer is best, thanks @Tom. `Locale.getDefault().toString()` – Fattie Dec 02 '16 at 14:33
-
4@Prizoff this post will help you https://stackoverflow.com/a/28498119/1263423 ,use `Resources.getSystem().getConfiguration().locale;` – wangqi060934 Jul 21 '17 at 14:44
-
1Downvoted the answer because it is not fully true as is specified in the comment to the initial question. The right one is given by Sarpe: you should use Resources to get system default language. – Prizoff Jul 21 '17 at 17:17
-
1I'd recommend against parsing a `toString` implementation to solve this problem, as recommended above. The Locale documentation "strongly discourages" this, but admits the implementation is stable enough that it shouldn't cause problems. In general, though, developers typically don't guarantee implementations of `toString` will remain stable. – Damien Diehl Aug 04 '17 at 04:05
-
[Locale.getLanguage()](https://developer.android.com/reference/java/util/Locale.html#getLanguage()), write `locale.getLanguage().equals(new Locale("he").getLanguage())` instead of, `if (locale.getLanguage().equals("he")) // BAD!` – ArtiomLK Feb 03 '18 at 04:24
-
2`Resources.getSystem().getConfiguration().locale ` works properly on Android 9. Locale.getDefault() always returns English! Beware! – Violet Giraffe Jul 05 '19 at 20:41
-
-
I thought I read somewhere in Apple docs that there is a signal upon app launch/foregrounding which alerts the programmer if the locale changed while the app was away. Is this true? Can somebody help jog my memory? – QED Jun 23 '20 at 20:08
-
If you want to get language of your current application then you can try this : context.getResources().getConfiguration().locale.getLanguage() – pravingaikwad07 Jul 05 '20 at 01:45
What worked for me was:
Resources.getSystem().getConfiguration().locale;
Resources.getSystem()
returns a global shared Resources object that provides access to only system resources (no application resources), and is not configured for the current screen (can not use dimension units, does not change based on orientation, etc).
Because getConfiguration.locale
has now been deprecated, the preferred way to get the primary locale in Android Nougat is:
Resources.getSystem().getConfiguration().getLocales().get(0);
To guarantee compatibility with the previous Android versions a possible solution would be a simple check:
Locale locale;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
locale = Resources.getSystem().getConfiguration().getLocales().get(0);
} else {
//noinspection deprecation
locale = Resources.getSystem().getConfiguration().locale;
}
Update
Starting with support library 26.1.0
you don't need to check the Android version as it offers a convenient method backward compatible getLocales()
.
Simply call:
ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration());

- 5,747
- 2
- 28
- 26
-
7getConfiguration().locale is currently deprecated, use getConfiguration().getLocales().get(0) instead – Eliseo Ocampos Jan 31 '17 at 13:39
-
8This is the correct answer to this question. other answers get local of the app, not the device. – hofs Aug 26 '17 at 16:40
-
9I don't know if this existed when the answer was written, but the support library has backwards compatible versions of this, there is no need to write backwards compatibility yourself. `ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration())` – Thorbear Feb 09 '18 at 09:21
-
As @Thorbear pointed out, now using the new support library method `getLocales` is the way to go. I've updated my answer. – Sarpe Feb 12 '18 at 17:38
-
3This is right answer. Others return the language of application not of system. – Chintan Rathod Jan 10 '19 at 05:29
You can 'extract' the language from the current locale. You can extract the locale via the standard Java API, or by using the Android Context. For instance, the two lines below are equivalent:
String locale = context.getResources().getConfiguration().locale.getDisplayName();
String locale = java.util.Locale.getDefault().getDisplayName();

- 6,033
- 6
- 37
- 46
-
12this is not true. They are different. The first can change if the user switches the Locale. The second is the one that is pre-installed on the phone. It never changes no matter what the user does. – gregm Nov 01 '11 at 21:20
-
16
-
5@gregm's comment is wrong. Just try it out yourself and you will see, that Locale.getDefault() will change when you change the language in settings. – Patrick Boos Nov 19 '14 at 07:07
-
Should see http://stackoverflow.com/questions/10657747/why-does-android-have-its-own-way-to-get-the-current-locale – Wernight Jan 09 '15 at 10:51
-
Although @gregm's comment is wrong, he still is right those two lines do not need to return the same locale. Just call `Locale.setDefault()` with some other locale beforehand and you get different results. – arekolek Feb 12 '19 at 21:40
-
Doesn't work on Android 9, always returns English. Only this works: https://stackoverflow.com/a/28498119/634821 – Violet Giraffe Jul 05 '19 at 20:42
-
This is not a solution that works always. There is difference between the app and the device language. If the device e.g. is set to Italian but the app does only supporting English (as default) and French, Locale will report English and not Italian. You can also manually set the app language using Configuration. Sarpe's answer is the better choice! – crysxd Jan 02 '21 at 07:58
-
Just wanted to add that, at least on my case it seems like the `Locale.getDefault()` option was more accurate in general for whatever reason. For most languages I picked, both options were giving the same codes, but when I changed the phone's language to Indonesian for example, I got "in_ID" using `Locale.getDefault()`, whereas with Android's resources config, I got "en_US". – César Muñoz Nov 25 '21 at 10:47
To save others time and/or confusion I wanted to share that I have tried the two alternatives proposed by Johan Pelgrim above and on my device they are equivalent - whether or not the default location is changed.
So my device's default setting is English(United Kindom) and in this state as expected both Strings in Johan's answer give the same result. If I then change the locale in the phone settings (say to italiano(Italia)) and re-run then both Strings in Johan's answer give the locale as italiano(Italia).
Therefore I believe Johan's original post to be correct and gregm's comment to be incorrect.
As described in Locale reference the best way to get language is:
Locale.getDefault().getLanguage()
this method returns string with language id according to ISO 639-1 standart

- 722
- 5
- 15
You can use this
boolean isLang = Locale.getDefault().getLanguage().equals("xx");
when "xx" is any language code like "en", "fr", "sp", "ar" .... and so on

- 3,097
- 36
- 34
-
3if (Locale.ENGLISH.equals(Locale.getDefault().getLanguage())) { ...} – Clement Martino Oct 28 '13 at 20:47
-
1@ClementMartino your suggestion is OK in case of Pre-defined Locales like ENGLISH, but for other locales like Arabic, we have to parse it using the lang code – Simon K. Gerges May 21 '17 at 06:14
if API level is 24 or above, use LocaleList.getDefault().get(0).getLanguage()
else use Locale.getDefault.getLanguage()
private fun getSystemLocale() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
LocaleList.getDefault().get(0).language
} else {
Locale.getDefault().language
}
reference: https://developer.android.com/guide/topics/resources/multilingual-support
This solution worked for me. This will return you the android device's language (not the app's local language)
String locale = getApplicationContext().getResources().getConfiguration().locale.getLanguage();
This will return "en" or "de" or "fr" or whatever your device language is set to.

- 1,477
- 1
- 13
- 23
To add to Johan Pelgrim's answer
context.getResources().getConfiguration().locale
Locale.getDefault()
are equivalent because android.text.format.DateFormat
class uses both interchangeably, e.g.
private static String zeroPad(int inValue, int inMinDigits) {
return String.format(Locale.getDefault(), "%0" + inMinDigits + "d", inValue);
}
and
public static boolean is24HourFormat(Context context) {
String value = Settings.System.getString(context.getContentResolver(),
Settings.System.TIME_12_24);
if (value == null) {
Locale locale = context.getResources().getConfiguration().locale;
// ... snip the rest ...
}
You can try to get locale from system resources:
PackageManager packageManager = context.getPackageManager();
Resources resources = packageManager.getResourcesForApplication("android");
String language = resources.getConfiguration().locale.getLanguage();

- 1,755
- 1
- 16
- 12
-
1This is THE answer in case you've overridden any part of the configuration – Takhion Jul 14 '15 at 16:17
If you want to check a current language, use the answer of @Sarpe (@Thorbear):
val language = ConfigurationCompat.getLocales(Resources.getSystem().configuration)?.get(0)?.language
// Check here the language.
val format = if (language == "ru") "d MMMM yyyy г." else "d MMMM yyyy"
val longDateFormat = SimpleDateFormat(format, Locale.getDefault())

- 26,736
- 15
- 188
- 224
-
If you want to apply user's local date format, use `DateFormat.getDateInstance(DateFormat.LONG, Locale.getDefault()).format(Date())`. – CoolMind May 21 '19 at 09:32
public void GetDefaultLanguage( ) {
try {
String langue = Locale.getDefault().toString(); // ---> en_US
/*
Log.i("TAG", Locale.getDefault().getLanguage() ); // ---> en
Log.i("TAG", Locale.getDefault().getISO3Language() ); // ---> eng
Log.i("TAG", Locale.getDefault().getCountry() ); // ---> US
Log.i("TAG", Locale.getDefault().getISO3Country() ); // ---> USA
Log.i("TAG", Locale.getDefault().getDisplayCountry() ); // ---> United States
Log.i("TAG", Locale.getDefault().getDisplayName() ); // ---> English (United States)
Log.i("TAG", Locale.getDefault().toString() ); // ---> en_US
Log.i("TAG", Locale.getDefault().getDisplayLanguage() ); //---> English
*/
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
langue = Locale.getDefault().toLanguageTag(); // ---> en-US
url_Api = getUrlMicrosoftLearn(langue);
Log.i("TAG", url_Api );
Log.i("TAG", langue );
}else{
langue = langue.replace("_","-"); // ---> en-US
url_Api = getUrlMicrosoftLearn(langue);
Log.i("TAG", url_Api );
Log.i("TAG", langue );
}
}catch (Exception ex) {
Log.i("TAG", "Exception:GetDefaultLanguage()", ex);
}
}
public String getUrlMicrosoftLearn(String langue) {
return "https://learn.microsoft.com/"+langue+"/learn";
}

- 677
- 6
- 7
-
It would be better if you could add more instructions to the answer, rather than just pasting the code. – Calos Feb 26 '20 at 00:31
Answers above don't distinguish between simple chinese and traditinal chinese.
Locale.getDefault().toString()
works which returns "zh_CN", "zh_TW", "en_US" and etc.
References to : https://developer.android.com/reference/java/util/Locale.html, ISO 639-1 is OLD.

- 8,084
- 8
- 48
- 62

- 101
- 4
The others have given good answers for the device language,
if you wish the app language the easiest way to do it is by adding an app_lang
key to your strings.xml
file, and specify the lang for each of the langs as well.
That way, if your app's default language is different from the device language, you can chose to send that as parameter for your services.

- 18,261
- 11
- 80
- 104
-
I can't believe there's no framework support for giving you the language the AssetManager is currently using. In fact, the String format helpers in Resources.java use the default locale[0] so if the string from the AssetManager comes from a locale that does not match the device's default locale (because your app does not support it but supports e.g. the next on the list) then there's a bug. – dcow Aug 02 '19 at 00:08
You can use this code to find out keyboard current
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodSubtype ims = imm.getCurrentInputMethodSubtype();
String locale = ims.getLocale();

- 4,637
- 39
- 52
- 71

- 252
- 3
- 5
If you choose a language you can't type this Greek may be helpful.
getDisplayLanguage().toString() = English
getLanguage().toString() = en
getISO3Language().toString() = eng
getDisplayLanguage()) = English
getLanguage() = en
getISO3Language() = eng
Now try it with Greek
getDisplayLanguage().toString() = Ελληνικά
getLanguage().toString() = el
getISO3Language().toString() = ell
getDisplayLanguage()) = Ελληνικά
getLanguage() = el
getISO3Language() = ell

- 8,084
- 8
- 48
- 62

- 5,472
- 3
- 33
- 35
public class LocalUtils {
private static final String LANGUAGE_CODE_ENGLISH = "en";
// returns application language eg: en || fa ...
public static String getAppLanguage() {
return Locale.getDefault().getLanguage();
}
// returns device language eg: en || fa ...
public static String getDeviceLanguage() {
return ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).get(0).getLanguage();
}
public static boolean isDeviceEnglish() {
return getDeviceLanguage().equals(new Locale(LANGUAGE_CODE_ENGLISH).getLanguage());
}
public static boolean isAppEnglish() {
return getAppLanguage().equals(new Locale(LANGUAGE_CODE_ENGLISH).getLanguage());
}
}
Log.i("AppLanguage: ", LocalUtils.getAppLanguage());
Log.i("DeviceLanguage: ", LocalUtils.getDeviceLanguage());
Log.i("isDeviceEnglish: ", String.valueOf(LocalUtils.isDeviceEnglish()));
Log.i("isAppEnglish: ", String.valueOf(LocalUtils.isAppEnglish()));

- 2,819
- 2
- 22
- 49
Please be careful, most of the answers here provides the language of the application. There can be cases where this application can have/set a different language than the device.
To get the actual device languages (Yes, if the user have multiple languages added in the settings, it will return all of it!)
Kotlin:
// Will return something like ["en_US", "de_DE"]
val deviceLanguages: LocaleListCompat = ConfigurationCompat.getLocales(Resources.getSystem().configuration)
// Will return the actual language in use, like "en" or "de". The first language in the above code will be the default language
val currentActiveDeviceLanguage = languages.get(0).language

- 1,992
- 2
- 19
- 34
Locale.getDefault().getLanguage() is VM language
Locale.getDefault().getLanguage()
It is the language of the current VM instance that is running your app. It is consumed by java classes such as DateFormat etc. You may need to modify this when changing app locale if you use certain java classes. If you have modified this during changing your App locale it is not the same as the language of android.
context.getConfiguration().locale.getLanguage() is Activity language
context.getConfiguration().locale.getLanguage()
This is the language set at your activity. In the latest SDK versions following is preferable
context.getConfiguration().getLocales().get(0).getLanguage()
Resources.getSystem().getConfiguration().getLocales() gives all locales that user has added at system level
This will give you the first locale that user has set at the system level.
Resources.getSystem().getConfiguration().getLocales().get(0).getLanguage()
A great number of users are multilingual so you may want to loop through Locales.

- 799
- 7
- 12
There are two languages.
Default language of OS:
Locale.getDefault().getDisplayLanguage();
Current language of Application:
getResources().getConfiguration().locale.getDisplayLanguage();//return string

- 44,500
- 61
- 101
- 156

- 71
- 2
- 4
-
4thats not true, if you change locale in your app even first give you changed value and not system value – To Kra Mar 29 '15 at 17:33
Locale.getDefault().getDisplayLanguage()
will give you Written
name for the Language, for example, English, Dutch, French
Locale.getDefault().getLanguage()
will give you language code
, for instance: en, nl, fr
Both methods return String

- 1,771
- 1
- 21
- 21
The correct way of getting the language of your device is the following:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return context.getResources().getConfiguration().getLocales().get(0);
} else {
return context.getResources().getConfiguration().locale;
}
Hope it helps.

- 1,167
- 1
- 13
- 33
My solution is like this
@SuppressWarnings("deprecation")
public String getCurrentLocale2() {
return Resources.getSystem().getConfiguration().locale.getLanguage();
}
@TargetApi(Build.VERSION_CODES.N)
public Locale getCurrentLocale() {
getResources();
return Resources.getSystem().getConfiguration().getLocales().get(0);
}
and then
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Log.e("Locale", getCurrentLocale().getLanguage());
} else {
Log.e("Locale", getCurrentLocale2().toString());
}
shown ---> en

- 33
- 7
here is code to get device country. Compatible with all versions of android even oreo.
Solution: if user does not have sim card than get country he is used during phone setup , or current language selection.
public static String getDeviceCountry(Context context) {
String deviceCountryCode = null;
final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if(tm != null) {
deviceCountryCode = tm.getNetworkCountryIso();
}
if (deviceCountryCode != null && deviceCountryCode.length() <=3) {
deviceCountryCode = deviceCountryCode.toUpperCase();
}
else {
deviceCountryCode = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()).get(0).getCountry().toUpperCase();
}
// Log.d("countryCode"," : " + deviceCountryCode );
return deviceCountryCode;
}

- 3,092
- 26
- 30
If you use jetpack compose
In side of composable functional
Context.applicationContext.resources.configuration.locales.get(0).language

- 1
- 1
you can use .setLanguage(Locale.forLanguageTag(Locale.getDefault().getLanguage())); it is good

- 21
- 2
The code bellow will return you the country code like US
Locale.getDefault().getCountry()

- 1
- 1
An updated answer for Jetpack compose, from within a @Composable
val locale = Locale.current
// locale.language

- 5,160
- 7
- 44
- 76
if(Locale.getDefault().getDisplayName().equals("हिन्दी (भारत)")){
// your code here
}

- 8,084
- 8
- 48
- 62

- 1,819
- 17
- 17
-
2Please add some details about why this answers the question - just code snippet will not help readers to understand the solution – Wand Maker Nov 24 '15 at 14:29
-
Locale.getDefault().getDisplayName() gives the current language of your device. and we are checking whether Device language is Hindi or not .. If current Device language is Hindi, then do what you want in the block. – Pratibha Sarode Jan 14 '16 at 06:41
-
This is hard coding. That is not how it should be handled. Whatever difference want to have across languages you need to do it via properties in the values-LL folders. – Sandeep Dixit Jun 12 '22 at 05:03
If you want to do specific task for users resides in India who speaks Hindi then use below if condition
if(Locale.getDefault().getDisplayName().equals("हिन्दी (भारत)")){
//Block executed only for the users resides in India who speaks Hindi
}

- 175
- 2
- 11