10

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.

Swanand
  • 12,317
  • 7
  • 45
  • 62
Santhi Bharath
  • 2,818
  • 3
  • 28
  • 42
  • 1
    Can you expand on what you mean by "not working" for those devices? Is it simply returning an empty array, an array with _only_ `Locale.US`, is it crashing, is it not returning locales you expect to be available? – Adam S Feb 25 '16 at 17:04
  • I updated my question, please check – Santhi Bharath Feb 29 '16 at 04:38
  • Okay, can I ask _why_ you need the locales? You should be displaying things with whatever locale your user has selected (ie the default locale) and writing to network or whatever with `Locale.US`, as [documented in the `Locale` docs](https://developer.android.com/reference/java/util/Locale.html). I recall something like you're experiencing (locales != installed languages), though I'm not sure what's going on with that. – Adam S Feb 29 '16 at 04:51

2 Answers2

6

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

Community
  • 1
  • 1
Narasimha
  • 759
  • 6
  • 8
5

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:

Adam S
  • 16,144
  • 6
  • 54
  • 81