Change Device language via ADB

2020-01-27 05:51发布

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

标签: android adb
10条回答
做个烂人
2楼-- · 2020-01-27 06:03

You can change the locale/language for testing purposes without rooting the 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.

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.

Finally, you can use adb commands (launch activity) to switch locale.

查看更多
男人必须洒脱
3楼-- · 2020-01-27 06:03

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.

https://github.com/dtmilano/AndroidViewClient/blob/480ab93dbd01296a68c1ce7109ceb8275d1ed8a7/src/com/dtmilano/android/viewclient.py#L1302

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.

查看更多
Viruses.
4楼-- · 2020-01-27 06:04

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.

And the script used:

adb shell "su 0 setprop persist.sys.locale ja";adb shell "su 0 setprop ctl.restart zygote"

May add ;sleep 20 in the end if some commands in script below this command depend on device to be ready.

查看更多
成全新的幸福
5楼-- · 2020-01-27 06:07

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
    
查看更多
等我变得足够好
6楼-- · 2020-01-27 06:10

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 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.

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:

adb shell "setprop persist.sys.locale fr-CA; setprop ctl.restart zygote"
查看更多
Viruses.
7楼-- · 2020-01-27 06:13

This is all over the place, to put it simply

setprop will only work on an AVD or a rooted physical device

The alternative is to use the settings in the Launcher.

Rooted device or AVD this works:

<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:/ #
查看更多
登录 后发表回答