Android辅助功能执行触摸操作

时间:2016-07-26 12:21:44

标签: android touch accessibility accessibilityservice

我想知道是否可以在位置屏幕上使用Android辅助功能服务执行触摸操作,例如:

Bundle arguments = new Bundle();
arguments.putInt(/*coord X*/, /*X value*/);
arguments.putInt(/*coord Y*/, /*Y value*/);
node.performAction(/*touch action*/, arguments);

或者,如果可能,再次记录用户点击某个视图/位置时的操作。

基本上,当弹出时,我必须对软键盘执行操作(外部应用程序没有“提交”按钮来执行ACTION_CLICK),但由于安全策略,不允许注入事件。任何的想法?谢谢!

2 个答案:

答案 0 :(得分:0)

您无法按屏幕上的位置执行任何操作,您只能在节点上执行任何操作,但您可以通过递归检查屏幕上的select a, b, c, d . . . 屏幕上的节点来查找坐标上的节点

如果它是OpenGL游戏,它将无法工作,并且您无法仅在您在该位置找到的节点上执行精确位置的点击。

答案 1 :(得分:0)

//touch function

public void touchTo(int x, int y) {
    Path swipePath = new Path();
    swipePath.moveTo(x, y);
    swipePath.lineTo(x, y);
    GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
    gestureBuilder.addStroke(new GestureDescription.StrokeDescription(swipePath, 0, 50));
    dispatchGesture(gestureBuilder.build(), null, null);
}

// 它在我的类 SupporterService 中工作,扩展了 AccessibilityService。