小编Ahm*_*med的帖子

获取当前正在运行的活动的实例

我想要做的是将动作事件发送到当前正在运行的活动.我从这段代码中获得了当前活动的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实例以便我可以发送事件?

events android android-activity

7
推荐指数
1
解决办法
2万
查看次数

通过windowmanger注入运动事件?

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

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)进行静态引用"

谁能帮我 !!

events android touch

6
推荐指数
1
解决办法
5044
查看次数

如何在屏幕上确定软按钮android

我正在研究android应用程序.我必须在屏幕上的特定位置设置图像.当出现在此图像中的屏幕按钮时出现问题!在此输入图像描述

我googled很多但没有找到任何帮助.是否有任何方式以编程方式检测屏幕按钮上的这些?谢谢您的帮助.

android uibutton

5
推荐指数
1
解决办法
1919
查看次数

标签 统计

android ×3

events ×2

android-activity ×1

touch ×1

uibutton ×1