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.
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.
dispatchTouchEvent(MotionEvent) - This allows your Activity to intercept all touch events before they are dispatched to the window.
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).
"Touch slop" refers to the distance in pixels a user's touch can wander before the gesture is interpreted as scrolling.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With