Android touch touch event

I know this is a slightly repeating question. I looked at various questions on SO and several other sites, but could not find a single answer that suits my needs.

Demand

1) I have X, Y coordinates, I want to create a MotionEvent and send it to the highest activity / view.

2) I have to enter it in my application. Therefore, < Inject_Events .. is not required.

3) As long as I have the coordinates, I do not know the activity or view that are in this position. Therefore Activity.dispatchTouchEvent does not work for me. . (view.dispatchTouchEvent will work, but I don't know the view).

4) The toolkit does not help , because they do not have a single method for entering a touch event at x, y.

5) InputManager has a hidden injectInputEvent method, but I don’t know how to access injectInputEvent and compile it?

Any help appreciated!

+7
android touch motionevent
source share
2 answers

In the interests of a larger group - rootViewController.dispatchTouchEvent (instead of activity.rootViewController) works like a charm.

+1
source share
dispatchTouchEvent(MotionEvent.obtain( SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, Xinput, Yinput, 0)); 

You do not need to specify a view, the event will be recorded in the foreground operation. Replace Xinput and Yinput with your values.

+5
source share

All Articles