cannot close recent apps using adb shell input keyevent - android

I use the following code:
adb shell input keyevent KEYCODE_APP_SWITCH
adb shell input keyevent 20
adb shell input keyevent DEL
the 1st line of code works.. it does indeed open the recent app window.. however i wanted it to press the close or X button
any idea ?

you should be able to do it using the following command
adb shell input tap x y
replace x and y with the X button position on the screen.

you may simulate swipe the screen with the following command
adb shell input swipe 500 500 500 1000 100

Related

Samsung Devices API 12 does not Dial code automatically

We are trying to dial the code
"*%2306%23" = "*#06#"
through the adb command to fetch the information about the IMEI
adb -s "DEVICE SERIAL" shell am start -a android.intent.action.DIAL -d tel:*%2306%23
The connected device shows the code on the screen but doesn't auto-dial. But, when we try to dial manually it's working fine.
The device is connected and the developer option is enabled.
Any help would be appreciated.
The intent that you are sending only opens the dialer app and enters the number, it does not dial. In order to dial you have to press the call button - adb shell input keyevent KEYCODE_CALL, but...
you are not dialing a regular number, you want to enter some code, so you have to open the dialer and enter the code symbol by symbol:
adb shell am start -a android.intent.action.DIAL
adb shell input keyevent KEYCODE_STAR
adb shell input keyevent KEYCODE_POUND
adb shell input keyevent KEYCODE_0
adb shell input keyevent KEYCODE_6
adb shell input keyevent KEYCODE_POUND

Batch Loop %Variable% times

I'm creating a batch file so I can easily control my phone using ADB
I have done most of it, however I want to be capable of controlling my volume level.
I know that adb shell input keyevent 25 decreases by 1 level, however is there a way of using variables to do it x amount of times?
So, I currently have:
cd C:\platform-tools-latest-windows\platform-tools
cls
title DECREASING Volume
cls
echo Decreasing Volume...
adb shell input keyevent 25
pause
cls
goto :USERAREA
If I were to ask the user for how many levels to decrease by, I would start with:
cd C:\platform-tools-latest-windows\platform-tools
cls
title DECREASE Volume
cls
set /p VOL=How many levels should it decrease by:
pause
echo Decreasing Volume...
adb shell input keyevent 25
pause
cls
goto :USERAREA
However, I don't know how to repeat the command adb shell input keyevent 25
%VOL% number of times.
Please help me with this,
Thank You
yg.swagness
for /L %%a in (1,1,%vol%) do adb shell input keyevent 25
see for /? from the prompt for documentation

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.

Bash script to launch app and login - gets stuck, cursor doesn't move down the page

What I want to do: Clear the data, then launch my app. On the first page, tab down and agree to conditions, then on next page tab down to the sign-in textfields, enter the username, password, then tap sign in.
What happens is the data is cleared, the app is launched, then the app just sits on the terms/conditions screen, and the cursor does not move down to the buttons.
What am I missing? Do I need to bring the focus to the screen so that the cursor gets a location before I move it?
#!/bash/src
adb shell pm clear com.myapp.package
adb shell am start -n com.myapp.package/com.myapp.package.Main
adb shell input keyevent 20
adb shell input keyevent 20
adb shell input keyevent 20
adb shell input keyevent 20
adb shell input keyevent 21
adb shell input keyevent 66
adb shell input text "username"
adb shell input keyevent 20
adb shell input text "password"
adb shell input keyevent 20
adb shell input keyevent 66
you could try sending a back button to see if you can dismiss the Terms and conditions:
adb shell input keyevent 4

How can I use adb to send a longpress key event?

I can use something like:
adb shell input keyevent 4
and this will send a single 'Back' button press to my device. How can I send a longpress?
Thanks
You can try this command:
adb shell input touchscreen swipe 170 187 170 187 2000
Your application position on screen is
170, 187; delay time is 2000 (ms);
Long press HOME key:
adb shell sendevent /dev/input/event2 1 172 1
adb shell sendevent /dev/input/event2 0 0 0
timeout 1
adb shell sendevent /dev/input/event2 1 172 0
adb shell sendevent /dev/input/event2 0 0 0
You can goto cmd and type adb shell getevent | find "event2" ; long press HOME key to see more.
Since this commit in Android 4.4 it is possibile to use:
adb shell input keyevent --longpress KEYCODE_L
This other commit further improved the behaviour.
When you want to delete something or repeat some Event or just input a lot of numbers, you can use code like the following. It will imitate a longpress on a keyboard:
adb shell input keyevent KEYCODE_FORWARD_DEL KEYCODE_FORWARD_DEL KEYCODE_FORWARD_DEL //delete 3 times
adb shell input keyevent KEYCODE_1 KEYCODE_1 KEYCODE_1 //input value '111'
You can repeat the event or input things without limits, just like a Longpress on the key. It's the same thing. You can define your own longpass and times Now
This link discusses a similar problem, but the device in question (a Nexus One device)has the menu/home/back/search buttons as part of the touchscreen, not physical keys.
This other one appears to be more inline with injecting a physical key input, but requires accessing the *.kl file for your devices driver to determine the device, type, key-code, value-press, and value-release codes for that specific device.
However, the common link between the two appears to be
adb shell sleep n
, where n is the length (in seconds) of the press duration.
Hopefully this might be of some use.
Well, this developer link show the keycode is 128, which i already test, but no expected result
You can check this link and this link. They show how to find it.
This might be too late to answer but surely will help others.
Please use below cmd to achieve long press.
adb shell input keyevent 5 sleep 5

Categories

Resources