如何使用 AccessibilityService 执行触摸并按住手势?

Aka*_*tak 6 android accessibilityservice android-studio

Path clickPath = new Path();
clickPath.moveTo(x, y);
GestureDescription.StrokeDescription clickStroke = new GestureDescription.StrokeDescription(clickPath, 0, 1);
GestureDescription.Builder clickBuilder = new GestureDescription.Builder();
clickBuilder.addStroke(clickStroke);
dispatchGesture(clickBuilder.build(), null, null);
Run Code Online (Sandbox Code Playgroud)

使用此代码,我可以在屏幕上的任何位置执行点击。有没有办法使用 AccessibilityService 执行触摸并按住手势?

小智 5

有没有办法使用 AccessibilityService 执行触摸并按住手势?

我认为你需要决定是否willContinue做出这个手势。然后,根据您的代码我建议更改:

GestureDescription.StrokeDescription clickStroke = new GestureDescription.StrokeDescription(clickPath, 0, 1);
Run Code Online (Sandbox Code Playgroud)

到:

GestureDescription.StrokeDescription clickStroke = new GestureDescription.StrokeDescription(clickPath, 0, 1, true);
Run Code Online (Sandbox Code Playgroud)

简单地,添加true到 的最后一个参数StrokeDescriptionPS:这仅适用于 Android 8+。