android - API 24 AccessibilityService.dispatchGesture() 方法如何工作?

标签 android accessibility

通过 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

关于android - API 24 AccessibilityService.dispatchGesture() 方法如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39283640/

相关文章:

java - 如何遍历 SparseArray?

Android/iOS 设置设备热点IP地址

android - Webrtc Android 摄像头捕获

android - LinearLayout 随机闪烁

java - 如何让我的 Java 8 应用程序启用 JAWS 以帮助盲人用户?

ios - TableViewCell 中的 UIButton VoiceOver 辅助功能

android - 自动 gradle 下载而不是 cordova 中的本地 gradle

android - ViewPager2 + 辅助功能 + 对讲问题,同时尝试更改焦点并使用滑动手势滚动

javascript - OnClick 和 OnKeyPress 符合标准

grails - GSP日期选择器:为每个字段(天,月,年)添加标签