API 24 AccessibilityService.dispatchGesture() 方法是如何工作的? [英] How does the API 24 AccessibilityService.dispatchGesture() method work?

查看:62
本文介绍了API 24 AccessibilityService.dispatchGesture() 方法是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过 API 24,我们获得了一种向设备发送手势的方法,但是目前还没有可靠的文档或示例.我正在尝试让它工作,但目前手势每次都点击onCancelled"回调.

With API 24 we got a way to dispatch a gesture to the device, however there is no solid documentation or examples out there yet. I am trying to get it to work but currently the gesture is hitting the "onCancelled" callback every time.

这是我调用该方法的代码:

Here is my code that calls the method:

@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();
}`

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

Has anyone used this new method yet or know of an example of how to get it functioning?

推荐答案

你的路径只是 lineTos,它没有指定起点.尝试将第一个更改为 moveTo.

Your path is just lineTos, which doesn't specify a starting point. Try changing the first one to a moveTo.

这篇关于API 24 AccessibilityService.dispatchGesture() 方法是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆