问题
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