简体   繁体   English

Android 辅助功能执行触摸操作

[英]Android Accessibility perform touch action

I am wondering if it is possible to perform touch action with Android accessibility service on screen at position, eg:我想知道是否可以使用 Android 无障碍服务在屏幕上的位置执行触摸操作,例如:

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

Or, again if possible, record an action when user taps on a certain view / position.或者,如果可能,再次记录用户点击某个视图/位置时的操作。

Basically, I have to perform action over soft keyboard, when it pops up (external app does not have "Submit" button to perform ACTION_CLICK on it), but injecting events is not permitted due to security policies.基本上,我必须在软键盘上执行操作,当它弹出时(外部应用程序没有“提交”按钮来执行 ACTION_CLICK),但由于安全策略,不允许注入事件。 Any idea?有什么想法吗? Thanks!谢谢!

You can not perform any action by position on the screen, you can only do on the nodes, but you can find which node is on your coordinates by recursively checking nodes position-on-the-screen with getBoundsInScreen .您不能按屏幕上的位置执行任何操作,您只能在节点上执行任何操作,但是您可以通过使用getBoundsInScreen递归检查屏幕上的节点位置来找到哪个节点在您的坐标上。

It wouldn't work if it is OpenGL game, and you won't be able to perform the click on the precise location only on the node you found on that location.如果它是 OpenGL 游戏,它将不起作用,并且您将无法仅在您在该位置找到的节点上执行对精确位置的单击。

//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);
}

// It working in my class SupporterService extends AccessibilityService. // 它在我的类 SupporterService 中工作,扩展了 AccessibilityService。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM