Occasionally, I am having trouble sending text to the emulator. It does not always write correctly what I have sent; it is as if it writes so quickly or reads so quickly that it does not finish writing the word
For example, if I write:
Monkey77
sometimes it is written correctly and sometimes it shows me
Mon
or any strange result but not the word Monkey.
I have been searching and documenting and find nothing that refers to this type of error. I have tried different android emulators and they all give me the same problem.
The command I'm using is: adb -s ip:port shell input text "Monkey77"
I've tried this command: adb -s ip:port shell input keyboard text "Monkey77" and I have the same problem.
I had the same issue and solved it by sending character by character:
adbinp() {
if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Sends the given text to the connected Android device." >&2
echo "Usage: adbinp [-h, --help] text ..." >&2
echo '' >&2
return 129
fi
echo "$*" | fold -w 1 | while read -r c; do
test -n "$c" || c="%s"
adb shell -n input text "\\$c"
done
}
Spaces will result in zero length lines by fold and need to be replaced by %s to encode them properly for adb shell.
We also prepend any character with an escape sequence to make special characters like # work. In my testing it seems to affect only special characters, so things like \n will not result in new lines, but still print the character n. The escape sequence logic seem to be custom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With