自动更改Android模拟器的语言环境 [英] Changing the Android emulator locale automatically

查看:400
本文介绍了自动更改Android模拟器的语言环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关自动测试(使用哈德森),我有一个生成一个一堆仿真器的Andr​​oid操作系统版本,屏幕分辨率,屏幕像素密度和语言的多种组合中的脚本。
这工作得很好,除了语言的一部分。

For automated testing (using Hudson) I have a script that generates a bunch of emulators for many combinations of Android OS version, screen resolution, screen density and language.
This works fine, except for the language part.

我需要找到一种方法来自动改变Android系统的语言环境。这里有一些方法我能想到的,在顺序preference:

I need to find a way to change the Android system locale automatically. Here's some approaches I can think of, in order of preference:

  • 在提取/编辑/直接启动模拟器前,重新包装一个QEMU映像
  • 在运行某种形式的系统语言环境变化启动后在模拟器APK
  • 更改模拟器上的文件系统区域设置启动后
  • 更改部分的SQLite数据库的区域设置启动后在模拟器上
  • 运行键序列(通过仿真器的远程登录界面),这将打开设置应用程序修改本地化
  • 手动的启动仿真器为每个平台版本,改变了区域的手的设置,将其保存和存档图像,之后部署
  • Extracting/editing/repacking a QEMU image directly before starting the emulator
  • Running some sort of system-locale-changing APK on the emulator after startup
  • Changing the locale settings on the emulator filesystem after startup
  • Changing the locale settings in some SQLite DB on the emulator after startup
  • Running a key sequence (via the emulator's telnet interface) that would open the settings app and change the locale
  • Manually starting the emulator for each platform version, changing the locale by hand in the settings, saving it and archiving the images for later deployment

任何想法是否可以做到这一点,可以通过上述方法或以其他方式?

Any ideas whether this can be done, either via the above methods or otherwise?

你知道在哪里的区域设置被保存到/从系统中读取?

Do you know where locale settings are persisted to/read from by the system?

解决方法:
关于相关性由于dtmilano的信息,并在我的一部分了进一步的调查,我想出了一个解决方案,甚至比上面所有的想法!

Solution:
Thanks to dtmilano's info about the relevant properties, and some further investigation on my part, I came up with a solution even better and simpler than all the ideas above!

我已经更新了他的答案下面的细节。

I have updated his answer below with the details.

推荐答案

我个人认为,最简单的方法是启动仿真器,可能是一个干净的情况下,除非你正在运行的集成测试依赖于其他应用程序,然后使用亚行更改语言环境

Personally I think the simplest way is to start the emulator, probably a clean instance unless you are running integration tests that depends on other applications and then change locale using adb:

$ adb shell '
setprop persist.sys.language en;
setprop persist.sys.country GB;
stop;
sleep 5;
start'

或其他区域要设置。 要验证你的改变是成功的只是使用

or whatever locale you want to set. To verify that your change was successful just use

$ adb shell 'getprop persist.sys.language'

您可能还需要运行在专门的端口仿真器,检查<一href="http://stackoverflow.com/questions/2214377/how-to-get-serial-number-or-id-of-android-emulator-after-it-runs">my回答这个线程。

You may also want to run emulators on know ports, check my answer in this thread.

请注意,您也可以直接设置系统属性的启动模拟器时:

Note that you can also set system properties directly when starting the emulator:

emulator -avd my_avd -prop persist.sys.language=en -prop persist.sys.country=GB

这种方式,你可以创建任何类型的普通老式模拟器然后立即使用您所选择的语言环境启动它,没有先不必进行任何修改仿真器的图像。

This way, you can create a plain old emulator of any type then start it up immediately using the locale of your choice, without first having to make any modifications to the emulator images.

这个区域将持续未来的仿真器的运行,不过当然你可以再在启动或运行时更改它。

This locale will persist for future runs of the emulator, though of course you can always change it again at startup or during runtime.

这篇关于自动更改Android模拟器的语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆