i would like to simulate touch on my anroid phone through a python code on my computer using the "adb shell tap x y" function (or any other way you may know). I have tried using
from subprocess import call
call(["adb", "kill-server"])
call(["adb", "shell"])
call(["input", "tap" , "1400" , "800"]) //example of x and y
but it just reaches the "shell" call and gets stuck.
(I know the tap function works because it works on the ordinary cmd window)
This should do it:
from subprocess import call
call(["adb", "shell", "input", "tap" , "1400" , "800"])
In your original script:
You start a remote shell on your Android device (adb shell)
After you quit the remote shell typing exit, you issue a command on your host computer shell (input tap 1400 800).
Instead you should use adb to redirect a command to the Android device's remote shell. To do that, just append the command after adb shell, for example adb shell input tap 1400 800. Take a look here.
I also removed the adb kill-process line because there is no kill-process adb command.
Related
I am trying to automate a txt file to be created and installed to an android phone.
Hi, I have created a batch file to automate a script, setting up a Sony device. The script works fine and is great, however I am now trying to create a Txt file that stores information of the version and date that the device was scripted within the internal memory.
So far, all I need to do is set the device to developer mode, enable USB debugging then double click the windows batch file and it runs as expected. the list of commands follow as such:
\
shell input tap 0358 1108 #all apps\
shell input tap 0610 0802 #settings\
shell input tap 0343 0427 #wifi\
shell input tap 0674 0101 #3 dots\
shell input tap 0437 0290 #advanced\
shell input tap 0630 0252 #network notification off \
shell input keyevent 4 #back\
shell input keyevent 4 #exit\
shell input tap 0350 0552 #bluetooth\
shell input tap 0635 0212 #on\
shell input keyevent 4 #exit\
shell input tap 0357 0871 #more\
shell input tap 0340 0410 #android beam\
shell input tap 0648 0198 #off .........
This continues further and again works great. What I am trying to achieve is that the script creates a Txt files within the SD card, so I can refer back to which version the script used in the many months to come. So far I can achieve the following by manually opening CMD.
adb shell \
shell#F3311:/ $ echo "#Sony_Script \t#Version 1.0 \n\n \t\t#08/11/2022" > /sdcard/Android/data/ScriptVersion.txt
This creates the file as expected within the directory. However I haven't got the time to do this manually for every device and would like this automated but it never seems to work.
I don't want to open adb shell every time to do this, I am hoping to implement it within the original batch file so it can run in the background. I hope this makes sense. Below is the windows batch file I have created.
setlocal ENABLEDELAYEDEXPANSION\
#echo off
REM adb command to grab all connected devices
adb devices > adb.txt
findstr /v "List of devices attached" adb.txt > clean.txt
for /f "tokens=*" %%a in (Version.txt) do (
for /f "tokens=1" %%b in (clean.txt) do (
echo adb -s %%b %%a
start adb -s %%b %%a
)
TIMEOUT /T 4
)
Maintain a script with version, something like
:
#Sony_Script
#Version 1.0
#08/11/2022
input tap 0358 1108 #all apps
input tap 0610 0802 #settings
input tap 0343 0427 #wifi
input tap 0674 0101 #3 dots
input tap 0437 0290 #advanced
input tap 0630 0252 #network notification off
...
then
adb push myscript /sdcard/
adb shell sh /sdcard/myscript
you will know exactly what was executed on each device
Is there anyway an app could detect if it was launched (or killed) via an ADB command line code from an attached computer vs physically tapping the actual app icon on the screen?
And/or could it tell if a tap input in the app was done by a physical tap vs an ADB input?
Launch command: adb shell monkey -p -c android.intent.category.LAUNCHER 1
Kill command: adb shell am force-stop
Tap command: adb shell input tap
adb command is running in a brandnew process of system/bin/sh. It is difficult to achieveļ¼even if the device is rooted.
You maybe need handle touch events via getevent command. adb shell input will skip the input device to simulate user action, but if someone uses the adb shell sendevent command, you will not be able to detect it.
Objective: I want to automate call related scenario using android uiautomator in android 6.0.1 devices. But not able to get UI hierarchy in incall screen (Mute, Spearker On, Keypad, Addcall etc.)
Note: I am not using any appium server
Error: "Error obtaining UI hierarchy" Reason: Error while obtaining UI
hierarchy XML file: com.android.ddmlib.SyncException: Remote object
doesn't exist!
Observations:
adb devices is listing the device and we can access /data/local/tmp/ directory
restarted device, restarted pc, relaunch of uiautomatorviewer
adb shell input tap x y is working (but don't want to use co-ordinates in scripts files)
please assist in finding a solution in order to automate phone app incall scenarios like "mute" , "unmute" , "dtmf pressing keypad numbers", "speaker on" speaker off".
Is there any way to perform such actions via adb ?
You can simply call adb command to invoke the caller service.
To dial (not call) a number from ADB, run the following ADB shell command:
$ adb shell service call phone 1 s16 "9302939203"
Result: Parcel(00000000 '....')
To make a call from ADB, we just need to change the way we call the service command:
$ adb shell service call phone 2 s16 "1" s16 "9302939203"
Result: Parcel(00000000 '....')
An alternative command is also there to make a phone call from ADB:
$ adb shell am start -a android.intent.action.CALL -d tel:9302939203
Starting: Intent { act=android.intent.action.CALL dat=tel:xxxxxxxxxxx }
Guys basically I've plugged in a bunch of Android devices to a computer and each of them has adb enabled. I'm running a shell script to push certain files to the devices using the Device Serial Numbers stored in a text file. When I trigger the script the first time it works. if i trigger it again adb throws an error , "error device not found" though the devices are still detected using adb. If i close the terminal and reopen it and run the script it works fine. I plan to eventually automate the script running. How can i stop this from happening.
EDIT: This is the piece of code where the adb shell commands are triggered
cat device_serial | while read line
do
adb -s $line shell
cd /data/
ls
exit
adb -s $line root
adb -s $line push 'stestfile.txt ' /data/
echo "done"
done
I need to look at the script to fix the issue.
But looks like the problem is that the next time you run the script, you are actually in the device's shell instead of your computer's.
I have a little script that I run in adb shell of Android phone (/system/etc directory), which enables to communicate with the modem by sending/receiving a single AT command.
The script itself, if run in adb shell, works OK. That's what it looks like:
cat /dev/pts/7 &
echo -e $1\\r > /dev/pts/7
Here's the output in adb shell:
# ./sendATCommand "at+cops?"
./sendATCommand "at+cops?"
#
+COPS: 0,0,"AT&T",6
OK
/dev/pts/7: invalid length
(need to press ENTER to return control to adb shell)
#
Now I want to invoke this script from a powershell script running on my PC, thus eventually controlling modem via AT commands, but nothing happens.
For example, the below powershell script will send the command at+cops? to check the operator to which mobile is registered to:
$adb = [IO.Path]::Combine([IO.Path]::Combine($Env:ANDROID, "platform-tools"), "adb.exe")
& $adb remount
$atCommand = "at+cops?"
& $adb shell /system/etc/sendATCommand $atCommand
The output may looks sometimes like +ATCMD (any residual [proprietary]AT command sitting in device buffer after bootup), or at+cops?(echo), or nothing at all, but
never +COPS: 0,0,"AT&T",6 which I expect. Could you help me figure out what's going on and how to possibly fix it? Ideally
I want to be able to execute at command, return control to powershell, and have output available for further processing.
I am also open to other solutions to implement same thing.
Would greatly appreciate your help. Thanks!
Not sure to answer your question, my phone is not an Android, but when I connect it via buetooth or USB to my computer a COM port is created. So I build an assembly tool on the top of .NET SerialPort class that allow, for example, to send SMS using the phone Modem.
I think it's usable in your case.