22

I know it's possible to have multiple languages in a single application through the res/string and depending on Locale. Here is a case (ANDROID) controling the user language

Now how can I change the language in the phone ? Like I'd do by Menu > Settings > Language & Keyboard > Select locale > languages

Is there some real code to access to these settings ? Or should I create intent for a shortcut to the language settings. Please post some code

Edit : With Locale class developer.android.com/intl/fr/reference/java/util/Locale.html

The constructor is at least Locale(String language) The input is language. How can you retrieve the current language used on the device ?

Community
  • 1
  • 1
Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110

5 Answers5

49

Not sure about setting it directly from the app, but if you want to send the user there to change it themselves, try this:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.settings", "com.android.settings.LanguageSettings");            
startActivity(intent);
Jim Blackler
  • 22,946
  • 12
  • 85
  • 101
  • Hey Jim, thanks very much. Just another question , how did you know about the package name and class name for settings ? – Raymond Chenon Apr 07 '10 at 23:40
  • 8
    What I did is to use my phone while connected to my PC on USB, and look at the logcat output. Every Intent started is logged to the output. The line read I/ActivityManager( 1018): Starting activity: Intent { act=android.intent.action.MAIN cmp=com.android.settings/.LanguageSettings } On a hunch I went onto Google Code Search and searched for "LanguageSettings Android Intent" and found an example of someone doing just this. I tested it myself and simplified the code for a snippet here. – Jim Blackler Apr 07 '10 at 23:55
  • I found another answer to my own question. There is an open source code project http://code.google.com/p/languagepickerwidget/ It's recreating a ListActivity to display and pick the languages. Jim , your solution is much simple and exactly what I needed. It's a shorcut to the settings. Immediately after you published, I uploaded an app called "raygional" on the market. If I could (I only have 6 points) I'd make your answer useful. There is another way to see the processes and intents. On the emulator go to Menu > Dev Tools > Development Settings > and click on Show running processes . – Raymond Chenon Apr 10 '10 at 14:42
  • 5
    startActivity(new Intent(Settings.ACTION_LOCALE_SETTINGS)) might be the better approach for some use cases because it directly opens the language list, also it's an officially defined action. – Markus Junginger Jul 17 '13 at 09:34
14

There is another way to open system settings to change the language:

Intent i = new Intent( android.provider.Settings.ACTION_LOCALE_SETTINGS );
startActivity( i );

It shows just the list of languages, and when you choose one - it changes the language on the device.

Sergey
  • 324
  • 4
  • 9
7

I found another answer to my own question. There is an open source code project code.google.com/p/languagepickerwidget It's recreating a ListActivity to display and pick the languages.

Jim , your solution is much simple and exactly what I needed. It's a shorcut to the settings. Immediately after you published, I uploaded an app called "raygional" on the market. If I could (I only have 6 points) I'd make your answer useful.

There is another way to see the processes and intents. On the emulator go to Menu > Dev Tools > Development Settings > and click on Show running processes

Cumbayah
  • 4,415
  • 1
  • 25
  • 32
Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110
  • Is there any other project similar to this one, which shows how to just change the locale of the OS, but with an Apache-license or something similar? – android developer Mar 29 '14 at 19:04
3

To expand on Jim's answer if you change the intent to:

intent.setClassName("com.android.settings", "com.android.settings.LocalePicker"); 

It will drop the user off directly in the language selection list and once a language is selected it will return to your application.

It removes a click, doesn't make the user think about which of the three (language, dictionary, and keyboard) options to choose and returns to your app immediately after selection.

caller9
  • 2,207
  • 1
  • 18
  • 11
  • didn't work on a Samsung Galaxy Tab 2 (causes ActivityNotFoundException: Unable to find explicit activity class). Is there maybe an updated intent available? – Jane Mar 11 '13 at 13:20
  • I used this with a try catch. Fallsback on another try catch using ACTION_LOCALE_SETTINGS intent. works great! – baskInEminence Jan 19 '21 at 08:05
3

As far as I know, the only way to change the Locale of the device without using Intents (what the other solutions propose) is accessing internal classes through reflection (with the risks that this implies).

You can find an exact example for this use case

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Edu Zamora
  • 1,492
  • 1
  • 19
  • 30