Fire double tap command to android device using adb - android

I have been trying to send a command to my device to double tap on the screen.
I tried to send this
adb shell input tap 600 1000
adb shell input tap 600 1000
However, it does not result into a doubletap.
Anyone willing to help me out?

This has worked for me pretty reliably until android 10; however, it no longer works on android 11 :(
I figured out a way to do it like this:
input tap <x> <y>&
sleep 0.1
input tap <x> <y>
as in
adb shell "input tap 520 1150& sleep 0.1; input tap 520 1150"
When digging around android 11 it seems that input command spawns up a JVM that is very slow, and it slowed down enough on android 11 to about 0.5 seconds, so the system does not recognize it as a double tap.
You can speed up the taps (or any user input) by including it in the same adb shell command. Previously I did this:
adb shell "input tap 520 1150; input tap 520 1150"
This will be easier on your system memory (as only one input command is executing at once) and may work pre android 11, but the one with & and explicit sleep between the two taps is what I switched to now.

Related

How can I open the dial pad during a call using adb?

When I need to see my doctor I have to:
Call to 666666666
Wait 5 seconds
Press 1
Wait 5 seconds
Press 20301990
Wait 5 secondos
Press 1
So I want to automatizate all this steps
I know that I can fire the call doing:
adb shell am start -a android.intent.action.CALL -d tel:666666666
and I can simulate a input by:
sleep 5
adb shell input text "1"
sleep 5
adb shell input text "20*30*1990"
sleep 5
adb shell input text "1"
but It can't work if I don't open de dial pad after adb shell am start -a android.intent.action.CALL -d tel:666666666 and before adb shell input text "1"
So my question is: How can I open the dial pad during a call using adb?
You can find the coordinates of the dial's pad button and then simulate a press by sending input tap x y.
If your automation will be used on multiple devices from different types, I would advise you to write a simple python script that uses uiautomator to do that task.

How to bring app to Foreground in calabash-android?

I am working on a application, it contain social share options. Whenever I tap on facebook it will open facebook app in the device with share view.
After that, I want to bring my application to foreground.
I tried pressing back button,
press_back_button()
it is unsuccessful.
Is there any way to bring application to foreground in Calabash-android?
You should be able to do it by sending keypresses and screen touches with ADB
adb shell input keyevent KEYCODE_APP_SWITCH to open the recent apps menu
adb shell input tap 300 300
Will send a tap event on the screen but you'll have to play around with the coordinates to get them in the right place.
EDIT:
I just tried on my phone with the following commands and can reopen the most recent app
adb shell input keyevent KEYCODE_APP_SWITCH
adb shell input tap 300 1700
Before trying these commands on your ruby code see if they work from the terminal (not irb).
The second command uses x and y coordinates that will be different depending on the size of the screen on your phone, 300 1700 works for me but you will need to try some different numbers to make it work for you.
To open the second most recent app, which I think is what you will need, I have to run adb shell input tap 300 700. You will need to play around with this and see what works for you.
FINAL EDIT: I've found a nicer way to do this that's not dependant on screen resolution.
adb shell input keyevent KEYCODE_APP_SWITCH
Then to find your app (you may need to send these multiple times to get it to work)
adb shell input keyevent KEYCODE_DPAD_UP
and/or
adb shell input keyevent KEYCODE_DPAD_DOWN
Then to select
adb shell input keyevent KEYCODE_ENTER
you need to run the system command, e.g.
system("adb shell input keyevent KEYCODE_APP_SWITCH”)
This willl open recent activities.

Issues running multiple Shells on Tasker for Android

I'm currently using Tasker on Android and I want to create a task using 2 Run Shell's. The setup I have is...
1.Wait
MS 0 Seconds 10 Minutes 0 Hours 0
2.Run Shell
Command input tap 550 580
3.Wait
MS 0 Seconds 10 Minutes 0 Hours 0
4.Run Shell
Command input tap 550 1800
Currently the first Run Shell works fine but the second Run Shell never executes. Don't understand why it's not running the second Run Shell.
there might be few reasons for that:
you are pointing wrong coordinates
app, you're trying to interact with, does not support accessibility features
you do not have accessibility features enabled
other
to achieve your goal, I'd recommend using Tasker's plugin called AutoInput
as it gives you way more control over what you click, focus, type etc

How to make a double tap to expand the video screen using android adb commands

I am trying to analyze a streaming video in my Android device. I want everything automated by scripts, because the device has to repeat the test a lot of times and I want to do it remotely (it is LAN connected). For that, I am using a special app, which starts to stream the video on a small-sized screen (it is special for that, I must expand the screen and I must use only this android app). A double-tap should be made to expand the screen (there is no button to expand, I can do it only double-tapping manually).
Due to my automation, I am trying to expand the video screen from a batch file when the video is streaming executing the following:
adb shell input tap x1 y1
adb shell input tap x1 y1
But it does not work. I've tried also with input touchscreen, input swipe x1 y1 x1 y1, I put every combination in a infinite loop, and it never expands. Maybe because the double tap it is too slow.... or maybe because that event needs to send a tap-release event.
Anybody encountered this problem already? How could I do a double tap to expand the screen remotely?
Thank you for your time!
Finally I got it. First I've recorded the double-tap event and stored it into a binary file:
adb shell
cd /sdcard/
cat /dev/input/event_X > doubletap
Do the doubletap wherever you want it, and then, end the recording with CTRL+C
The event_X is the event called sec_touchscreen.
It can be got from:
adb shell getevent -p
Then, you can replay the doubletap with:
adb shell "cat /sdcard/doubletap > /dev/input/event_X"
In my case, it was tricky because it did not work executing once the replay, but two, like:
adb shell "cat /mnt/sdcard/doubletap > /dev/input/event_X"
adb shell "cat /mnt/sdcard/doubletap > /dev/input/event_X"

How to use ADB to send touch events to device using sendevent command?

I am trying to send touch events to a device using AndroidDebugBridge, so that I can do some basic automation for UI tests. I have followed the discussion in LINK. I am able to use sendevent to simulate touch on emulators, but unable to do the same on a device.
Like in above link the emulator seems to send out 6 events for each touch ( xcoord, ycoord, 2 for press,2 for release) and it was easy to use this information to sendevents, but a getevent for the touchscreen for a device seems to generate far too many events.
Has somebody managed to send touch from ADB to a device? Could you please share the solution.
Android comes with an input command-line tool that can simulate miscellaneous input events. To simulate tapping, it's:
input tap x y
You can use the adb shell ( > 2.3.5) to run the command remotely:
adb shell input tap x y
In order to do a particular action (for example to open the web browser), you need to first figure out where to tap. To do that, you can first run:
adb shell getevent -l
Once you press on the device, at the location that you want, you will see this output:
<...>
/dev/input/event3: EV_KEY BTN_TOUCH DOWN
/dev/input/event3: EV_ABS ABS_MT_POSITION_X 000002f5
/dev/input/event3: EV_ABS ABS_MT_POSITION_Y 0000069e
adb is telling you that a key was pressed (button down) at position 2f5, 69e in hex which is 757 and 1694 in decimal.
If you now want to generate the same event, you can use the input tap command at the same position:
adb shell input tap 757 1694
More info can be found at:
https://source.android.com/devices/input/touch-devices.html
http://source.android.com/devices/input/getevent.html
2.3.5 did not have input tap, just input keyevent and input text
You can use the monkeyrunner for it: (this is a copy of the answer at https://stackoverflow.com/a/18959385/1587329):
You might want to use monkeyrunner like this:
$ monkeyrunner
>>> from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
>>> device = MonkeyRunner.waitForConnection()
>>> device.touch(200, 400, MonkeyDevice.DOWN_AND_UP)
You can also do a drag, start activies etc.
Have a look at the api for MonkeyDevice.
You don't need to use
adb shell getevent -l
command, you just need to enable in Developer Options on the device [Show Touch data] to get X and Y.
Some more information can be found in my article here: https://mobileqablog.wordpress.com/2016/08/20/android-automatic-touchscreen-taps-adb-shell-input-touchscreen-tap/
Building on top of Tomas's answer, this is the best approach of finding the location tap position as an integer I found:
adb shell getevent -l | grep ABS_MT_POSITION --line-buffered | awk '{a = substr($0,54,8); sub(/^0+/, "", a); b = sprintf("0x%s",a); printf("%d\n",strtonum(b))}'
Use adb shell getevent -l to get a list of events, the using grep for ABS_MT_POSITION (gets the line with touch events in hex) and finally use awk to get the relevant hex values, strip them of zeros and convert hex to integer. This continuously prints the x and y coordinates in the terminal only when you press on the device.
You can then use this adb shell command to send the command:
adb shell input tap x y
Consider using Android's uiautomator, with adb shell uiautomator [...] or directly using the .jar that comes with the SDK.

Categories

Resources