I wanted the shell to write the following text:
''Hello, it's been great.''
I managed to write
Hello, its been great.
with:
adb shell input text 'Hello,%sits%sbeen%sgreat.'
Any ideas if it is possible to write the (') signal? Before Hello two of them, in it's and in the end.
From the doc for ADB:
“adb shell setprop foo ‘a b’” command is now an error because the single quotes (‘) are swallowed by the local shell, and the device sees “adb shell setprop foo a b”. To make the command work, quote twice, once for the local shell and once for the remote shell, the same as you do with ssh(1). For example, “adb shell setprop foo “‘a b’””
So just do:
adb shell input text "''Hello,%sit's%sbeen%sgreat.''"
I'm trying to get from the device (running android L) the country and the language with the following commands:
adb shell getprop persist.sys.country
adb shell getprop persist.sys.language
But both return a empty string.
When I try another getprop command, like:
adb shell getprop ro.product.model
It returns the correct value.
Anyone knows what is happening?
Found the solution:
Android has changed this prop name in the last versions. You can use now:
adb shell getprop ro.product.locale
or
adb shell getprop persist.sys.locale
There are some other useful commands related to this question:
adb shell getprop ro.csc.country_code //e.g. [Germany]
adb shell getprop ro.csc.countryiso_code //e.g. [DE]
adb shell getprop ro.csc.sales_code //e.g. [VD2]
It gives information about country and operator the Binary is dedicated to (if not modified of course).
Hi I need to run things in the form of adb shell <command>
When I test everything out inside adb shell, it works because I was able to set some aliases in .bashrc.
However, when I do adb shell <command>, nothing works because .bashrc is not used when you run adb shell <command>, because it's in the non-interactive mode.
How can I work around this? Can I adb push some files to the filesystem so that the alias will be there when adb shell is run?
If your android device is rooted you can add your aliases for adb shell into the /system/etc/mkshrc file.
One way to do this is to issue several shell commands in a single ADB command. You can put them in a string, and separate them with semicolons, thus:
adb shell "alias foo bar ; export MY_VARIABLE=/path/to/somewhere ; my_executable "
The " are crucial here, make sure they are paired up correctly. You could run your .bashrc this way, thus:
adb shell "source /path/to/.bashrc ; my_executable"
You can write a bash script that sets the aliases and then executes your shell:
#!/usr/bin/bash
. $HOME/.bashrc
adb shell $#
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
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"
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.
There is few solutions.It works for me.
1.
adb shell am start -a android.settings.LOCALE_SETTINGS
(You could see the language menu, then choose language by appium)
2.
download adbchangelanguage on google store
adb shell pm grant net.sanapeli.adbchangelanguage android.permission.CHANGE_CONFIGURATION
adb shell am start -n net.sanapeli.adbchangelanguage/.AdbChangeLanguage -e language zh -e country TW
https://gist.github.com/douglasselph/b9998e69998759c6cceec1df1aa96ac5
3.
using appium then set desired capabilities (language and locale)
http://appium.io/docs/en/writing-running-appium/caps/
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
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:/ #
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.
To set the language to US English, run the following command in the terminal:
adb shell "setprop persist.sys.locale en-US; setprop ctl.restart zygote"
To change to other languages, refer this list of languages:
https://developers.google.com/interactive-media-ads/docs/sdks/android/client-side/localization#locale-codes
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.
According to official documents:
To change the locale in the emulator by using the adb shell.
Pick the locale you want to test and determine its BCP-47 language tag, for example, Canadian French would be fr-CA.
Launch an emulator.
From a command-line shell on the host computer, run the following command:
adb shell
or if you have a device attached, specify that you want the emulator by adding the -e option:
adb -e shell
At the adb shell prompt (#), run this command:
setprop persist.sys.locale [BCP-47 language tag];stop;sleep 5;start
Replace bracketed sections with the appropriate codes from Step 1.
For instance, to test in Canadian French:
setprop persist.sys.locale fr-CA;stop;sleep 5;start
This causes the emulator to restart. (It looks like a full reboot, but it isn't.) Once the Home screen appears again, re-launch your app, and the app launches with the new locale.
In case this helps someone: I changed my phone's language to something buggy called en-XA (it was called English one in the UI I believe?) by mistake, and I couldn't even unlock the screen, but I had to fix my language settings somehow. I had no root access, but I had a custom recovery (TWRP) flashed fortunately.
The solution for me was to edit the /data/system/users/0/settings_system.xml file, this line in particular:
<setting id="24885" name="system_locales" value="en-XA,pl-PL" package="android" defaultValue="en-XA,pl-PL" defaultSysSet="true" preserve_in_restore="true" />
I changed the en-XA to en-US, rebooted, and the phone works again!
You can edit the file using your recovery's built-in file editor or use /adb pull /data/system/users/0/settings_system.xml to download and edit the file locally, then adb push settings_system.xml /data/system/users/0/settings_system.xml to update it on the device.
BTW I also changed the en-XA to en-US in the /data/property/persistent_properties file before and it didn't work alone, but perhaps both are needed.
Everything tested on a clean Android 11 device.
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
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.
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
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.
On your device directly, you need a rooted device.
I have created a script to mount partitions and do some stuff in my Android system. I saved the script as install.sh in the /bin folder of Android.
I want to call the script from ADB, which is itself called from a batch file on Windows, but it needs to be executed as root.
The first solution I tried was to call the script using
adb shell "su -c sh /bin/script.sh"
but it does not work as it gives me a shell access (with root permissions), but nothing is executed.
I also tried to call
adb root "sh /bin/script.sh"
but I got the following error
adbd cannot run as root in production builds
I then tried to write
su -c "command"
for all the commands which need a root access in my script, but I have the same problem.
When I run the script I only obtain a root shell and nothing is executed.
If I use the first solution by hand (e.g. I call adb shell su, then my script), it works. However the whole point is to automate the process, so that adb shell can be called from another script.
Do you have any idea of how I could achieve this ?
Thanks !
This works for me:
Create myscript.bat and put into it (note the single quotes around the commands to be executed in superuser mode):
adb shell "su -c 'command1; command2; command3'"
then run myscript.bat from a DOS shell.
Note: it doesn't appear that the the DOS line continuation character (^) works in this situation. In other words, the following doesn't work for me:
adb shell "su -c '^
command1; ^
command2; ^
command3'"
This results in "Syntax error: Unterminated quoted string"
This works :
adb shell echo command which needs root privileges \| su
If you need redirection:
adb shell echo 'echo anytext > /data/data/aforbiddenfolder/file' \| su
For "copying" a local file to an android path needing root privileges (but alocalfile must not contain '):
cat alocalfile | adb shell echo "echo '`cat`' > /data/data/aforbiddenfolder/file" \| su
If you have a better way (even for su versions which don't have -c), I am interested.
This works for me:
adb shell "su -c ./data/local/tcpdump-arm -s 0 -v -w /data/local/appxpress_dump.pcap"
I am not sure if I provided a solution or asked for a better one.
I wanted to run some 200 command in batch mode to be sent to adb
I followed this approach
adb shell "su -c command ; "
adb shell "su -c command ; "
adb shell "su -c command ; "
adb shell "su -c command ; "
and I saved them in a batch file
This command
adb shell "su -c 'command1; command2; command3'"
will not work beyond a certain max size . It did not work
error: service name too long
but it does not work as it gives me a shell access (with root permissions), but nothing is executed.
How do you know that you are given root permissions? I assume you are attempting to execute the script on a device? Has your device been rooted?
You may need to give execute permissions via chmod to the file.
chmod ugo=rwx /bin/script.sh
It appears that I was using a very simple version of su which did not accept the -c argument.
I copied another su which did work. AndyD is totally right though, so I am accepting his answer instead of mine :)