通过windowmanger注入运动事件?

Ahm*_*med 6 events android touch

我想模拟触摸事件.我正在使用此代码

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);
Run Code Online (Sandbox Code Playgroud)

问题出在这条线上

windowManager.injectPointerEvent(event, false);
Run Code Online (Sandbox Code Playgroud)

我无法访问WindowManger.当我尝试使用它

 WindowManager windowmanager=(WindowManager) Context.getSystemService(Context.WINDOW_SERVICE);
Run Code Online (Sandbox Code Playgroud)

我收到了一条错误消息."无法从类型Context中对非静态方法getSystemService(String)进行静态引用"

谁能帮我 !!

arn*_*rhs 0

这个错误:I received an error message . "Cannot make a static reference to the non-static method getSystemService(String) from the type Context"是你的问题。

您需要获得对上下文的引用。应用程序上下文或活动。

一旦有了 Context 实例,就可以调用.getSystemService它的方法。