Skip to content Skip to sidebar Skip to footer

How Can I Get A List Of Languages Which Are Enabled By The User In Their Android Device?

How can I get a list of the languages which the user has added to their device? In the example below, the user has gone to device settings and added two languages. How can I progra

Solution 1:

LocaleListCompat llc = ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration());
for (int i=0; i<llc.size(); i++){
    System.out.println(llc.get(i).getDisplayLanguage());
}

This has backward compatiblity with versions. And llc will have all selected language by the user.

If you want full list of supported languages you will get it using Locale

for (Locale locale : Locale.getAvailableLocales()) {
        System.out.println("HELLO " + locale.getDisplayLanguage());
    }

Solution 2:

On Android 7.0 (API level 24) and above, you should call LocaleList.getDefault(). On earlier versions of Android, there was only an option to pick one language, which you can get via Locale.getDefault().

Solution 3:

For languages selected by user -

privatefungetSystemLocale(): String {
    returnif (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        return LocaleList.getDefault().get(0).getLanguage();
    } else {
        return Locale.getDefault.getLanguage();
    }
}

If you want to get the selected language of your device with below options:

Locale.getDefault().getDisplayLanguage();
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

Solution 4:

Here is the API to get all the available locales of your device.

public static Locale[] getAvailableLocales () For more information please check this public link : http://developer.android.com/reference/java/util/Locale.html#getAvailableLocales()

Solution 5:

Kotlin version. This is almost the same as suggested by (Shubham Agarwal Bhewanewala). Only with sorting and first capital letter.

val language = ArrayList<String>()
val llc = ConfigurationCompat.getLocales(Resources.getSystem().configuration)
for (i in0 until llc.size()) {
    
    language.add(llc[i].displayLanguage.substring(0,1).uppercase(Locale.getDefault()) + llc[i].displayLanguage.substring(1)

}
valset: Set<String> = HashSet(language)
language.clear()
language.addAll(set)
language.sort()

It will turn out like this: English French Russian Ukrainian and so on

Post a Comment for "How Can I Get A List Of Languages Which Are Enabled By The User In Their Android Device?"