Issue
I want to implement a click on my app programmatically. For doing that I thought of implementing the adb command for touch. The command is:
adb shell input tap x y
This command works on my adb shell, but i cant figure out a way of implementing it programmatically.
I tried the below piece of code:
private void runShellCommand(String command) throws Exception {
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
}
But I am getting this error in the debugger:
java.io.IOException: Cannot run program "adb": error=13, Permission denied
Could someone please help me with this!
PS: Even if you know other methods of programmatically touching the screen with the help of providing x and y coordinates please do help!
Solution
I am assuming that you want to touch something inside your app.
Capture an ACTION_DOWN MotionEvent (through the debugger from a touch action) and note its properties (down time, event time, and the meta state). This would only need to be done once to figure out what sort of values you should use to simulate a typical touch event.
In your test program, create a new MotionEvent with MotionEvent.obtain()
MotionEvent newTouch = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN,
x, y, metaState);
Dispatch the event on your view:
view.dispatchTouchEvent(newTouch);
You can try this. I have been using this for my own android test app.
Answered By - Pronoy999
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.