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