使用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();
}`
有没有人使用过这种新方法或知道如何使其运作的例子?
最佳答案 您的路径只是lineTos,它没有指定起点.尝试将第一个更改为moveTo.