首先在xml中增加设置
- [/code] 重点是 android:canPerformGestures="true"
- 详细代码
- [code] @RequiresApi(api = Build.VERSION_CODES.N) public static boolean clickByNode(AccessibilityService service, AccessibilityNodeInfo nodeInfo) { if (service == null || nodeInfo == null) { return false; } Rect rect = new Rect(); nodeInfo.getBoundsInScreen(rect); int x = (rect.left + rect.right) / 2; int y = (rect.top + rect.bottom) / 2; Point point = new Point(x, y); GestureDescription.Builder builder = new GestureDescription.Builder(); Path path = new Path(); path.moveTo(point.x, point.y); builder.addStroke(new GestureDescription.StrokeDescription(path, 0L, 100L)); GestureDescription gesture = builder.build(); boolean isDispatched = service.dispatchGesture(gesture, new AccessibilityService.GestureResultCallback() { @Override public void onCompleted(GestureDescription gestureDescription) { super.onCompleted(gestureDescription);// LogUtil.d(TAG, "dispatchGesture onCompleted: 完成..."); } @Override public void onCancelled(GestureDescription gestureDescription) { super.onCancelled(gestureDescription);// LogUtil.d(TAG, "dispatchGesture onCancelled: 取消..."); } }, null); return isDispatched; }
复制代码 如果执行到 onCancelled 里,表现失败,需要看看xml是否设置乐成
来源:https://blog.csdn.net/linzhiji/article/details/111941975
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |