【问题标题】:Simulating click via Android Accessibility Service通过 Android Accessibility Service 模拟点击
【发布时间】:2019-11-02 03:30:12
【问题描述】:

我正在尝试使用 Accessability Service 在 android 应用程序中模拟点击功能。我已经在清单中设置了该服务,并在我的手机设置中启用了它。我有一个类 MouseAccessabilityService,它包含以下点击功能:

// Clikc function that clicks at a specific x and y coordinate
@RequiresApi(api = Build.VERSION_CODES.N)
public static GestureDescription click(float x, float y) {
    // for a single tap a duration of 1 ms is enough
    final int DURATION = 1;

    Path clickPath = new Path();
    clickPath.moveTo(x, y);
    GestureDescription.StrokeDescription clickStroke =
            new GestureDescription.StrokeDescription(clickPath, 0, DURATION);
    GestureDescription.Builder clickBuilder = new GestureDescription.Builder();
    clickBuilder.addStroke(clickStroke);
    return clickBuilder.build();
}

我通过按下触发点击的按钮调用 MainActivity 中的点击函数(用于测试目的):

Buttonclick = (Button)findViewById(R.id.clickbutton);

    Buttonclick.setOnClickListener(new View.OnClickListener() {
        @RequiresApi(api = Build.VERSION_CODES.N)
        @Override
        public void onClick(View view) {
            //changeButtonText.setText("Second Text");
            MouseAccessabilityService.click(centerX, centerY);
        }
    });

X 和 Y 是从其他一些功能作为整数变量传递的。我似乎无法在我的应用程序中使用 click() 函数并按下按钮。

我在正确的页面上吗?这个功能甚至可以工作吗?我对此停滞不前,希望能提供任何帮助。

谢谢。

【问题讨论】:

  • 你能成功吗?

标签: java android


【解决方案1】:

您可以使用 dispatchGesture 函数。

尝试将点击函数的返回替换为: return dispatchGesture(clickBuilder.build(), null, null);

https://codelabs.developers.google.com/codelabs/developing-android-a11y-service/#7

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-24
    相关资源
    最近更新 更多