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.
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With