'How to perform a touch and hold gesture using 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);

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



Solution 1:[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+.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1