我想模拟触摸事件。我正在使用此代码
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);
问题在于这一行
windowManager.injectPointerEvent(event, false);
我无法访问WindowManger。当我尝试使用这个
时 WindowManager windowmanager=(WindowManager) Context.getSystemService(Context.WINDOW_SERVICE);
我收到了一条错误消息。 “无法从类型Context”
中对非静态方法getSystemService(String)进行静态引用任何人都可以帮助我!!
答案 0 :(得分:0)
此错误:I received an error message . "Cannot make a static reference to the non-static method getSystemService(String) from the type Context"
是您的问题。
您需要获取对上下文的引用。应用程序上下文或活动。
一旦有了Context实例,就可以在其上调用.getSystemService
方法。