自动更改 Android 模拟器区域设置 [英] Changing the Android emulator locale automatically

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

问题描述

对于自动化测试(使用 Hudson),我有一个脚本可以为 Android 操作系统版本、屏幕分辨率、屏幕密度和语言的多种组合生成一堆模拟器.
这工作正常,除了语言部分.

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 系统区域设置.以下是我能想到的一些方法,按优先顺序排列:

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 DB 中的区域设置
  • 运行一个按键序列(通过模拟器的 telnet 界面)打开设置应用并更改语言环境
  • 手动为每个平台版本启动模拟器,在设置中手动更改语言环境,保存并存档图像以供以后部署
  • 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.

推荐答案

我个人认为最简单的方法是启动模拟器,可能是一个干净的实例,除非您正在运行依赖于其他应用程序的集成测试,然后使用 adb 更改语言环境:

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'

您可能还想在已知端口上运行模拟器,请查看 我在这个线程中的回答.

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

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

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天全站免登陆