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

标签 android android-studio accessibilityservice

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

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

最佳答案

Is there any way to perform touch and hold gesture using AccessibilityService?



我认为您需要确定手势 willContinue 或不。然后,根据您的代码,我建议更改:
GestureDescription.StrokeDescription clickStroke = new GestureDescription.StrokeDescription(clickPath, 0, 1);

至:
GestureDescription.StrokeDescription clickStroke = new GestureDescription.StrokeDescription(clickPath, 0, 1, true);

只需添加 trueStrokeDescription 的最后一个参数. PS :这仅适用于 Android 8+。

关于android - 如何使用 AccessibilityService 执行触摸并按住手势?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59555188/

相关文章:

具有多个 jpeg 文件的 Android 动画?

php - 使用 Retrofit 发送图像文件帖子?

android-studio - 动画选择器导致 View 初始化时崩溃

java - 如何读取窗口内容(使用accessibilityService)并在Android中使用draw over other app权限唤起UI?

java - AccessibilityNodeInfo in getRoot ActiveWindow : Perform click fails with Rect() not contains X, Y坐标

android - 应用程序是否可能在一段时间后自行卸载?

java - 你会如何计算你的android项目中的 Activity 数量?

android-studio - 等待 30 秒 com.google.common.util.concurrent.SettableFuture@1e023601[status=PENDING]

android - Admob 测试 ID 不断变化

AccessibilityService 中的 Android onAccessibilityEvent 未被调用