Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

programmatically execute Touch event in android

Tags:

android

Can we execute touch event programmatically in android by some method, such as passing screen co-ordinates(x,y)? Is there any such method? Please guide me.

like image 460
kunal Avatar asked Mar 20 '12 13:03

kunal


People also ask

How does Android detect touch?

Android supports detecting certain common gestures including single tap, double tap, long press, scroll and fling with GestureDetector . Implement an OnGestureListener , attach it to a GestureDetector and use it inside the View's OnTouchListener by passing it each touch event the View receives.

What is dispatchTouchEvent?

dispatchTouchEvent(MotionEvent) - This allows your Activity to intercept all touch events before they are dispatched to the window.

How do you create a motion event?

You should use one of the static obtain methods of the MotionEvent class to create a new event. API Docs: Create a new MotionEvent, filling in a subset of the basic motion values. Those not specified here are: device id (always 0), pressure and size (always 1), x and y precision (always 1), and edgeFlags (always 0).

What is touch slop?

"Touch slop" refers to the distance in pixels a user's touch can wander before the gesture is interpreted as scrolling.


1 Answers

I am not sure if it works, but try this:

MotionEvent event = MotionEvent.obtain(downTime, eventTime, action, 
                                       x, y, pressure, size, 
                                       metaState, xPrecision, yPrecision, 
                                       deviceId, edgeFlags);
onTouchEvent(event);
like image 179
Dmytro Danylyk Avatar answered Oct 11 '22 13:10

Dmytro Danylyk