小编Nic*_*ito的帖子

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

使用 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();
}`
Run Code Online (Sandbox Code Playgroud)

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

android accessibility

6
推荐指数
1
解决办法
4731
查看次数

标签 统计

accessibility ×1

android ×1