Switch language programmatically on an Android device

Jimmy Collins picture Jimmy Collins · Dec 13, 2011 · Viewed 7k times · Source

I'm writing some Android test automation for our applications, which are localized into 18 languages.

I need the ability to switch the language on the device programmatically - I don't mean to switch the language of just the application - I mean switch the actual device language in the Android settings, that way our application switches also.

Is there any way I can accomplish this via MonkeyRunner, the Android Debug Bridge or otherwise? Ideally I'd like a way that works on both the android emulator, and a physical device.

Thanks.

Answer

Jimmy Collins picture Jimmy Collins · Jan 5, 2012

Finally figured out you can do this via the Android Debug Bridge which I've just installed on my test machine and added to the windows PATH variable.

For example, the command to switch the device language to German would be:

adb shell "su -c 'setprop persist.sys.language de; setprop persist.sys.country de; stop; sleep 5; start'

You will need a rooted device in order for this to work.