I want to make a small app that, with one or two clicks, will switch the system language between two, three or more prefered languages, selected before-hand from the "official" language list, i.e. the one that appears in Quick settings > Settings > Language & input > Language.
How do I get this list programatically? Is this the locale list, available from Locale.getAvailableLocales()? Should I get to the languages from the locales? Thank you!
EDIT - This is what I've done so far:
private List<Model> getModel() {
Locale[] locales = Locale.getAvailableLocales();
List<Model> list = new ArrayList<Model>();
for (int i=0; i<locales.length; i++) {
list.add(get(locales[i].getDisplayLanguage()));
}
return list;
}
private Model get(String s) {
return new Model(s);
}
I'm looking those options now:
Locale.getDefault().getLanguage() ---> en
Locale.getDefault().getISO3Language() ---> eng
Locale.getDefault().getCountry() ---> US
Locale.getDefault().getISO3Country() ---> USA
Locale.getDefault().toString() ---> en_US
Locale.getDefault().getDisplayLanguage() ---> English
Locale.getDefault().getDisplayCountry() ---> United States
Locale.getDefault().getDisplayName() ---> English (United States)
from here.
EDIT 2 - 2 more images, showing the end of the languages list, where reside the options for chinese.
This is the list from the system.
This list was done with the following code:
Locale[] locales = Locale.getAvailableLocales();
List<Model> list = new ArrayList<Model>();
for (int i=0; i<locales.length; i++) {
list.add(get(locales[i].getDisplayLanguage()+"|"+
locales[i].toString()+"|"+
locales[i].getDisplayName()
));
}
return list;
Now there must be a way to get to the first list from the second list, perhaps accessing some system hidden files?
EDIT 3 - I added the following code and it shows the chinese, portuguese and spanish special characters (UTF-8) without problem:
list.add(get("Português (Brasil)"));
list.add(get("English (US)"));
list.add(get("中国(简体)"));
list.add(get("Español (Venezuela)"));
Now how do I get from here to actually change the system language (without opening the intent/activity like below?
Intent intent = new Intent(Settings.ACTION_LOCALE_SETTINGS);
startActivity(intent);
Here is the API to get all the available locales of your device.
For more information please check this public link : http://developer.android.com/reference/java/util/Locale.html#getAvailableLocales()