I am trying to write a batch(for win) and a shell script for linux to automate key and touch events on a android UI. At the moment in a windows batch file I am starting a adb shell for each event for eg
:again
adb shell am start -a android.intent.action.MAIN -n com.q.me.fui.activity/.InitActivity
sleep 15
adb shell sendevent /dev/input/event0 3 0 281
adb shell sendevent /dev/input/event0 3 1 70
adb shell sendevent /dev/input/event0 1 330 1
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 1 330 0
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 1 330 1
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 1 330 0
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 0 0 0
adb shell sendevent /dev/input/event0 0 0 0
sleep 5
adb shell input keyevent 82
adb shell input keyevent 20
adb shell input keyevent 20
adb shell input keyevent 22
adb shell input keyevent 22
adb shell input keyevent 22
adb shell input keyevent 66
sleep 5
goto again
The above code is infact starting a new adb shell each time. I want to avoid this. I want my batch script to start the adb shell only once and I would like to route the sendevent and other commands to the subshell, ie the adb shell.
Any idea how I can do this in win batch and Lin shell script?
Another way to go is the following:
I am doing something similar
So it may work as below:
I don't know much about batch scripting or shell scripting, but I was able to quickly write a java program to do this:
You can then use this class in a shell script as you like passing the commands to execute as command line arguments in your main method.
e.g. Below is the shell script:
Topher's answer is almost correct.
Just remove the newlines and it will work.
The only thing you need to take care of is, that you do not feed in more than 25 (that's the amount I used, 30 doesn work anymore) sendevents, because else adb will throw the error, that there are too many arguments or so.
Put all the commands you want to run at once in an external file, one per line, then run: