How to perform a touch and hold gesture using AccessibilityService?

回眸只為那壹抹淺笑 提交于 2021-01-28 05:13:13

问题


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

With this code I can perform clicks anywhere on the screen. Is there any way to perform touch and hold gesture using AccessibilityService?


回答1:


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

I think that you need decide if the gesture willContinue or not. Then, based in your code i suggest change:

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

To:

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

Simply, add true to last parameter of StrokeDescription. PS: this works only from Android 8+.



来源:https://stackoverflow.com/questions/59555188/how-to-perform-a-touch-and-hold-gesture-using-accessibilityservice

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!