简体   繁体   English

如何使用 AccessibilityService 执行触摸和保持手势?

[英]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?有没有办法使用 AccessibilityService 执行触摸和保持手势?

Is there any way to perform touch and hold gesture using AccessibilityService?有没有办法使用 AccessibilityService 执行触摸和保持手势?

I think that you need decide if the gesture willContinue or not.我认为您需要决定手势是否会willContinue 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 .简单地,将true添加到StrokeDescription最后一个参数。 PS : this works only from Android 8+. PS :这仅适用于 Android 8+。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM