通过windowmanger注入移动事件? [英] Inject motion event via windowmanger?

查看:180
本文介绍了通过windowmanger注入移动事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想模拟触摸事件。我用这code

i want to simulate 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);

问题是这一行

the problem is with this line

windowManager.injectPointerEvent(event, false);

这是我无法获得访问WindowManger。当我尝试使用此

that i am unable to get access to WindowManger . When i try to use this

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

我收到一条错误信息。 不能让一个静态引用非静态方法getSystemService(字符串)从类型上下文

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

谁能帮我!

推荐答案

此错误:我收到一条错误信息。 不能让一个静态引用非静态方法getSystemService(字符串)从类型上下文是你的问题。

您需要获得一个参考上下文。无论是应用程序上下文或活动。

You need to get a reference to the context. Either the application context or the activity.

一旦你有一个上下文实例,就可以调用它的 .getSystemService 方法。

once you have a Context instance, you can call the .getSystemService method on it.

这篇关于通过windowmanger注入移动事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆