Is there any way to simulate keyevent on "OK" or "CANCEL" buttons of Android dialogue box using adb commands?
Asked
Active
Viewed 5,989 times
2 Answers
6
One indirect way is:-
adb shell uiautomator dump /data/view.xml
adb shell cat /data/view.xml
calculate OK button coordinates from the relative coordinates given in the xml file. Then do
adb shell input tap <x> <y>
Hope works.

Rilwan
- 2,251
- 2
- 19
- 28
-
uiautomator wont work in all the mobiles.For me it works in Galaxy S4 and not works in Galaxy S3 – Fresher Jul 12 '13 at 11:57
-
1I have tried in almost all customer platforms except LG,It worked well.I am not sure about yours. Androidviewclient is another way. – Rilwan Jul 13 '13 at 09:06
3
Using AndroidViewClient/culebra you can simply do:
- run
java -jar androidviewclient-2.3.25.jar culebra --verbose --verbose-comments --find-views-with-text=true --output=myscript.py
- edit
myscript.py
and addvc.findViewWithTextOrRaise('Cancel').touch()
at the end (you can delete the unnecessary finds too)

Diego Torres Milano
- 65,697
- 9
- 111
- 134
-
What is the way if device is secure and we dont have the Application source code ? Is there any way to disable secure feature ? – Fresher Jul 22 '13 at 06:56
-
Your options are described in https://github.com/dtmilano/AndroidViewClient/wiki/Secure-mode – Diego Torres Milano Jul 22 '13 at 15:16