辅助功能服务dispatchGesture无法按预期工作,它只是偶尔执行手势?

Thi*_*ika 6 android accessibility android-service

我正在尝试构建一个带有光标的单手选项替代方案,以使用光标到达 Android 设备的高端。我使用触摸侦听器通过屏幕下半部分的跟踪器跟踪移动并识别用户的点击,并尝试在指针所在的位置执行这些点击。它有时有效,有时无效,我不明白为什么?

我已在服务元数据中包含 android:canPerformGestures="true" 。

这是我用来执行点击手势的代码

        // duration must be set in ms according to long click or simple click
        long duration;
        if (isLongClick){
            duration = 400L;
        }else{
            duration = 103L;
        }

        GestureDescription.Builder builder = new GestureDescription.Builder();

        Point point = new Point(cursorParams.x,cursorParams.y);

        Path path = new Path();
        path.moveTo( point.x, point.y);
        path.lineTo( point.x + 50, point.y + 50);

        GestureDescription.StrokeDescription clickStroke =
                new GestureDescription.StrokeDescription(path,10, duration);

        builder.addStroke(clickStroke);
        GestureDescription description = builder.build();
        boolean isDispatched = dispatchGesture(description, new GestureResultCallback() {
            @Override
            public void onCompleted(GestureDescription gestureDescription) {
                super.onCompleted(gestureDescription);
                Log.d("GestureClick","Gesture completed successfully");
            }

            @Override
            public void onCancelled(GestureDescription gestureDescription) {
                super.onCancelled(gestureDescription);
                Log.d("GestureClick","Gesture failed");
            }
        },null);
Run Code Online (Sandbox Code Playgroud)

我尝试更改开始时间和持续时间,并更改带和不带 lineTo 语句的路径。但事情最终都会有同样的结果。我还尝试在捕获手势的触摸侦听器中返回 true 或 false,以防它中断调度手势。

在所有这些尝试中,结果都是相同的,有时手势会在屏幕上的预期位置上执行点击,但大多数时候不会。它总是捕获 GestureResultCallback 上的 onCompleted 方法。