Android 通过 ADB 更改设备语言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21712205/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change Device language via ADB
提问by user3258796
I want to change language via ADB. I try:
我想通过亚行更改语言。我尝试:
adb shell setprop persist.sys.language fr;setprop persist.sys.country CA;stop;sleep 5;start
but I get errors:
但我收到错误:
setprop: command not found
stop: missing job name
Try `stop --help' for more information.
start: missing job name
Try `start --help' for more information.
what is wrong? I want to do this on physical device
怎么了?我想在物理设备上执行此操作
回答by Alex P.
Your errors have nothing to do with adb
. You just lack understanding of how your local shell processes your command. What you are doing is running these commands locally (on your PC):
您的错误与adb
. 您只是不了解本地 shell 如何处理您的命令。您正在做的是在本地(在您的 PC 上)运行这些命令:
adb shell setprop persist.sys.language fr
setprop persist.sys.country CA
stop
sleep 5
start
and the error messages you see are from local shell (i.e. there is no setprop
executable on your system and start
and stop
commands have non-optional parameters.
并且您看到的错误消息来自本地 shell(即setprop
您的系统上没有可执行文件,start
并且stop
命令具有非可选参数。
the correct command would be
正确的命令是
adb shell "setprop persist.sys.language fr; setprop persist.sys.country CA; setprop ctl.restart zygote"
or in more recent Android versions:
或在更新的 Android 版本中:
adb shell "setprop persist.sys.locale fr-CA; setprop ctl.restart zygote"
回答by Juuso Ohtonen
You can change the locale/language for testing purposes without rootingthe device, also on newer (4.2+) devices. You have to create an application that changes the device locale. Or, you can use a helper app, e.g. ADB Change Language.
您可以更改区域设置/语言以进行测试,而无需植根设备,也可以在较新的 (4.2+) 设备上进行。您必须创建一个更改设备区域设置的应用程序。或者,您可以使用辅助应用程序,例如ADB Change Language。
Next, on 4.2+ devices, you have to use grant the app CHANGE_CONFIGURATION permission via adb, adb shell pm grant <package_name> android.permission.CHANGE_CONFIGURATION
.
接下来,在 4.2+ 设备上,您必须通过 adb, 使用授予应用程序 CHANGE_CONFIGURATION 权限adb shell pm grant <package_name> android.permission.CHANGE_CONFIGURATION
。
Finally, you can use adb commands (launch activity) to switch locale.
最后,您可以使用 adb 命令(启动活动)来切换语言环境。
回答by Tricia
This is all over the place, to put it simply
这到处都是,简单地说
setprop will only work on an AVD or a rooted physical device
setprop 仅适用于 AVD 或有根物理设备
The alternative is to use the settings in the Launcher.
另一种方法是使用启动器中的设置。
Rooted device or AVD this works:
有根设备或 AVD 这有效:
<android-sdk path>/platform-tools/adb shell
root@generic:/ # getprop persist.sys.language
getprop persist.sys.language
en
root@generic:/ # setprop persist.sys.language fr
setprop persist.sys.language fr
root@generic:/ # setprop persist.sys.country CA
setprop persist.sys.country CA
root@generic:/ # stop
stop
root@generic:/ # start
start
root@generic:/ # sleep 5
sleep 5
root@generic:/ # getprop |grep lang
getprop |grep lang
[persist.sys.language]: [fr]
root@generic:/ # getprop |grep country
getprop |grep country
[persist.sys.country]: [CA]
root@generic:/ #
回答by Marco Acierno
Try this
尝试这个
adb shell "su -c 'setprop persist.sys.language fr; setprop persist.sys.country CA; stop; sleep 5; start'
You need a rooted device.
你需要一个有根的设备。
回答by niti
Run through the following steps:
执行以下步骤:
- Create emulator with google APIs Intel x86
Root the emulator, by running the command:
adb root
Run the following shell command through
adb
:adb -e shell "su root; setprop persist.sys.locale pt-PT; stop; sleep 2; start”
then, exit the shell which restarts the emulator.
Locales we need for screenshots:
de_DE en_EN fr_FR ko_KO pt_PT es_ES ja_JA
- 使用 google APIs Intel x86 创建模拟器
通过运行以下命令来根模拟器:
adb root
通过以下方式运行以下 shell 命令
adb
:adb -e shell "su root; setprop persist.sys.locale pt-PT; stop; sleep 2; start”
然后,退出重新启动模拟器的外壳。
我们需要截图的语言环境:
de_DE en_EN fr_FR ko_KO pt_PT es_ES ja_JA
回答by KNewman Liuu
There is few solutions.It works for me.
解决方案很少。它对我有用。
1.
1.
adb shell am start -a android.settings.LOCALE_SETTINGS
(You could see the language menu, then choose language by appium)
adb shell am start -a android.settings.LOCALE_SETTINGS
(你可以看到语言菜单,然后通过appium选择语言)
2.
2.
download adbchangelanguage on google store
在谷歌商店下载 adbchangelanguage
adb shell pm grant net.sanapeli.adbchangelanguage
adb shell pm grant net.sanapeli.adbchangelanguage
android.permission.CHANGE_CONFIGURATION
android.permission.CHANGE_CONFIGURATION
adb shell am start -n net.sanapeli.adbchangelanguage/.AdbChangeLanguage -e language zh -e country TW
adb shell am start -n net.sanapeli.adbchangelanguage/.AdbChangeLanguage -e language zh -e country TW
https://gist.github.com/douglasselph/b9998e69998759c6cceec1df1aa96ac5
https://gist.github.com/douglasselph/b9998e69998759c6cceec1df1aa96ac5
3.
3.
using appium then set desired capabilities (language and locale) http://appium.io/docs/en/writing-running-appium/caps/
使用 appium 然后设置所需的功能(语言和语言环境) http://appium.io/docs/en/writing-running-appium/caps/
回答by Vinayaka
The solution to do it without rooting. You can use something like this the below function. The function goes into settings and exercises the UI to change the locale settings.
无需生根即可完成的解决方案。您可以使用以下功能。该函数进入设置并练习 UI 以更改区域设置。
The tricky part is to get to the right language when you are in a different language. You would think the language always maintain the same index in the list, but unfortunately not. So you have to have a solution like this.
棘手的部分是当您使用不同的语言时使用正确的语言。你会认为语言总是在列表中保持相同的索引,但不幸的是不是。所以你必须有这样的解决方案。
Con: You my have to tweak it a little for handling different phones, the settings may have a different order.
缺点:您必须稍微调整它以处理不同的手机,设置可能有不同的顺序。
回答by vbevans94
On Emulator:When changed language manually, it stopped working and had to do wipe data of Emulator in AVD manager to make it work again.
在模拟器上:手动更改语言时,它停止工作,必须在 AVD 管理器中擦除模拟器的数据才能使其再次工作。
And the script used:
使用的脚本:
adb shell "su 0 setprop persist.sys.locale ja";adb shell "su 0 setprop ctl.restart zygote"
May add ;sleep 20in the end if some commands in script below this command depend on device to be ready.
如果此命令下面的脚本中的某些命令依赖于设备准备就绪,则可以在最后添加;sleep 20。
回答by user7367641
For Android M or newer, you need use:
对于 Android M 或更新版本,您需要使用:
setprop ro.product.locale xx-XX
setprop persist.sys.locale xx-XX
xx is language, XX is country
xx 是语言,XX 是国家
回答by Luser_k
You cant do that with the adb on your device. Your adb outside the device, I mean on your computer connected with usb, can change it with passing a permission before changing the language.
你不能用你设备上的 adb 来做到这一点。您在设备外的 adb,我的意思是在您与 USB 连接的计算机上,可以通过在更改语言之前传递权限来更改它。
On your device directly, you need a rooted device.
直接在您的设备上,您需要有根设备。