我想要做的是将动作事件发送到当前正在运行的活动.我从这段代码中获得了当前活动的ComponentName
ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
// get the info from the currently running task
List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
Log.d("current task :", "CURRENT Activity ::" +
taskInfo.get(0).topActivity.getClassName());
ComponentName componentInfo = taskInfo.get(0).topActivity;
Run Code Online (Sandbox Code Playgroud)
现在我有了组件名称,我想调度该事件
dispatchTouchEvent(MotionEvent ev)
Run Code Online (Sandbox Code Playgroud)
在Activity课堂上,要做到这一点,我需要一个当前活动的实例.我被困在组件名称.如何获取Activity实例以便我可以发送事件?
我想模拟触摸事件.我正在使用此代码
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)进行静态引用"
谁能帮我 !!
我正在研究android应用程序.我必须在屏幕上的特定位置设置图像.当出现在此图像中的屏幕按钮时出现问题!
我googled很多但没有找到任何帮助.是否有任何方式以编程方式检测屏幕按钮上的这些?谢谢您的帮助.