Change Device language via ADB

前端 未结 11 2341
温柔的废话
温柔的废话 2020-11-28 12:16

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

相关标签:
11条回答
  • 2020-11-28 12:37

    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:/ #
    
    0 讨论(0)
  • 2020-11-28 12:39

    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.

    0 讨论(0)
  • 2020-11-28 12:44

    For Android M or newer, you need use:

    setprop ro.product.locale xx-XX
    setprop persist.sys.locale xx-XX
    

    xx is language, XX is country

    0 讨论(0)
  • 2020-11-28 12:50

    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
      
    0 讨论(0)
  • 2020-11-28 12:50

    The solution for API 28+ is

    adb shell am broadcast -a com.android.intent.action.SET_LOCALE --es com.android.intent.extra.LOCALE "en_US" com.android.customlocale2
    
    0 讨论(0)
  • 2020-11-28 12:51

    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"
    
    0 讨论(0)
提交回复
热议问题