Reputation: 3304
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.
Upvotes: 9
Views: 7421
Reputation: 534
You can write a script, which sends a broadcast to a helper app like adb send broadcast and this app changes your configuration inside the device like device language where you can use that code of @iSun.
Upvotes: 0
Reputation: 3304
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.
Upvotes: 4
Reputation: 1754
You can change the local like this :
Resources res = context.getResources();
// Change locale settings in the app.
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale(language_code.toLowerCase());
res.updateConfiguration(conf, dm);
Upvotes: 1