Enter a motion event through a window?

I want to simulate a touch event. I am using this code

MotionEvent.PointerCoords[] coords = { new MotionEvent.PointerCoords() }; coords[0].x = 200; coords[0].y = 200; int[] ptrs = { 0 }; MotionEvent event =MotionEvent.obtain(SystemClock.uptimeMillis(),SystemClock.uptimeMillis(), action, 1, ptrs, coords, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHPAD, 0); windowManager.injectPointerEvent(event, false); 

problem with this line

 windowManager.injectPointerEvent(event, false); 

that I cannot access WindowManger. When I try to use this

  WindowManager windowmanager=(WindowManager) Context.getSystemService(Context.WINDOW_SERVICE); 

I received an error message. "It is not possible to make a static reference to the non-static method getSystemService (String) of type Context"

Can someone help me !!

+6
source share
1 answer

This error: I received an error message . "Cannot make a static reference to the non-static method getSystemService(String) from the type Context" I received an error message . "Cannot make a static reference to the non-static method getSystemService(String) from the type Context" is your problem.

You need to get a link to the context. Either the application context or the action.

after you have a context instance, you can call it .getSystemService .

0
source

Source: https://habr.com/ru/post/913954/


All Articles