Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the API 24 AccessibilityService.dispatchGesture() method work?

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?

like image 947
Nick Yelito Avatar asked Sep 02 '16 02:09

Nick Yelito


1 Answers

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

like image 157
Phil Weaver Avatar answered Oct 17 '22 20:10

Phil Weaver