Question

I know this is a bit repeating question. I have reviewed various questions on SO and few other sites but could not find a single answer that satisfies my need.

Requirement

1) I have X,Y coordinates, I want to create MotionEvent and dispatch it to topmost activity/view.

2) I have to inject it in my own App. So Inject_Events permission should not be required.

3) While I have the coordinates, I do not know, Activity or View which are at that position. So Activity.dispatchTouchEvent does not work for me.. (view.dispatchTouchEvent will work but I do not know the view).

4) Instrumentation does not help either because they do not have single method to inject touch event at x,y location.

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

Any help appreciated!

Était-ce utile?

La solution 2

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

Autres conseils

dispatchTouchEvent(MotionEvent.obtain(
                    SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                    MotionEvent.ACTION_DOWN, Xinput, Yinput, 0));

You do not need to specify a view, the event will register to the foreground activity. Replace Xinput and Yinput with your values.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top