Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android How to get system's installed locales

Tags:

android

locale

Is there any way to get System installed locales from the Android device. I tried with getAvailableLocales () from android Get Available locales, but it is not working for devices like Asus, Carbon, Lava, Intex.

For example, if I call getAvailableLocales() in Nexus device I am able to get locales which is there in Settings-> Language&Input -> Language

But if I do same on any Carbon device, instead of getting languages from Settings-> Language&Input -> Language, I get a different list.

I want only the installed list of languages in the device, not every language supported by OS.

like image 738
Santhi Bharath Avatar asked Feb 23 '16 13:02

Santhi Bharath


People also ask

How do I find the current language of my device?

This example demonstrate about how to Get the current language in Android device. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

What is device locale?

Device locale - Android Tutorial Locale is the representation of a specific region.

What is use locale default?

When the Java virtual machine starts running on a computer, it creates an object called the default locale. This object affects the format of strings created from data. Depending on the default locale, a program creates different strings for the same number.


2 Answers

If you want system supported locales, use

Locale.getAvailableLocales() 

If you want system supported and device enabled locales

Resources.getSystem().getAssets().getLocales()

By using the first one, you cannot be sure about if all locales are supported by that device. Cause they all came in with that Android ROM.

But the latter one is always a sure shot. Cause it gives only what all the locales(fonts) installed for that particular device. These locales(fonts) are placed by that device manufacturer.

I explained more it in here

like image 98
Narasimha Avatar answered Oct 18 '22 15:10

Narasimha


The Locale.getAvailableLocales() method is the generic 'base' set of locales. From the documentation:

Most locale-sensitive classes offer their own getAvailableLocales method, which should be preferred over this general purpose method.

Emphasis mine.

You can get the locales available for a specific use-case by querying the getAvailableLocales() method on the appropriate class. Specifically:

  • BreakIterator.getAvailableLocales()
  • Collator.getAvailableLocales()
  • DateFormat.getAvailableLocales()
  • DateFormatSymbols.getAvailableLocales()
  • DecimalFormatSymbols.getAvailableLocales()
  • NumberFormat.getAvailableLocales()
  • Calendar.getAvailableLocales()
like image 41
Adam S Avatar answered Oct 18 '22 17:10

Adam S