Android无障碍服务点击按钮

时间:2019-05-25 15:15:14

标签: android accessibilityservice ontouch

因此,我使用Accessibility Service来帮助用户在手机上执行某些功能,并帮助他们快速设置某些应用程序,今天我遇到了在Android交换机上将此设置importantForAccessibility: false;设置为true的应用程序,因此当我的应用程序按下视图位置时,不会为用户打开开关(就像按钮甚至没有在该按钮上一样),但是如果我手动触摸它,一切正常。我知道它在触摸正确的位置,因为我在手机上启用了开发人员选项以显示触摸。我的代码有问题吗,我可以使用另一种方法,还是可以做其他事情?

public boolean pressLocation(final int x, final int y)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
    {
        GestureDescription.Builder builder = new GestureDescription.Builder();
        Path p = new Path();    p.moveTo(x, y);
        builder.addStroke(new GestureDescription.StrokeDescription(p, 50, 100L));
        GestureDescription gesture = builder.build();
        dispatchGesture(gesture, null, null);

        dispatchGesture(gesture, new GestureResultCallback() {
            @Override
            public void onCompleted(GestureDescription gestureDescription) {
                super.onCompleted(gestureDescription);

            }

            @Override
            public void onCancelled(GestureDescription gestureDescription) {
                super.onCancelled(gestureDescription);
            }
        }, null);
    }

    return true;
}

0 个答案:

没有答案
相关问题