API 24 AccessibilityService.dispatchGesture()方法如何工作?

时间:2016-09-02 02:53:40

标签: android accessibility

使用API​​ 24,我们得到了一种向设备发送手势的方法,但是还没有可靠的文档或示例。我正试图让它工作,但目前的姿态正在击中" onCancelled"每次回调。

以下是调用方法的代码:

@TargetApi(24)
private void pressLocation(Point position){
    GestureDescription.Builder builder = new GestureDescription.Builder();
    Path p = new Path();
    p.lineTo(position.x, position.y);
    p.lineTo(position.x+10, position.y+10);
    builder.addStroke(new GestureDescription.StrokeDescription(p, 10L, 200L));
    GestureDescription gesture = builder.build();
    boolean isDispatched = dispatchGesture(gesture, new GestureResultCallback() {
        @Override
        public void onCompleted(GestureDescription gestureDescription) {
            super.onCompleted(gestureDescription);
        }

        @Override
        public void onCancelled(GestureDescription gestureDescription) {
            super.onCancelled(gestureDescription);
        }
    }, null);

    Toast.makeText(FingerprintService.this, "Was it dispatched? " + isDispatched, Toast.LENGTH_SHORT).show();
}`

有没有人使用过这种新方法或者知道如何让它运作的例子?

1 个答案:

答案 0 :(得分:2)

您的路径仅为lineTo s,未指定起点。尝试将第一个更改为moveTo