Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Accessibility perform touch action

I am wondering if it is possible to perform touch action with Android accessibility service on screen at position, e.g.:

Bundle arguments = new Bundle();
arguments.putInt(/*coord X*/, /*X value*/);
arguments.putInt(/*coord Y*/, /*Y value*/);
node.performAction(/*touch action*/, arguments);

Or, again if possible, record an action when user taps on a certain view / position.

Basically, I have to perform action over soft keyboard, when it pops up (external app does not have "Submit" button to perform ACTION_CLICK on it), but injecting events is not permitted due to security policies. Any idea? Thanks!

like image 541
Oleg Novosad Avatar asked Oct 16 '25 16:10

Oleg Novosad


2 Answers

//touch function

public void touchTo(int x, int y) {
    Path swipePath = new Path();
    swipePath.moveTo(x, y);
    swipePath.lineTo(x, y);
    GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
    gestureBuilder.addStroke(new GestureDescription.StrokeDescription(swipePath, 0, 50));
    dispatchGesture(gestureBuilder.build(), null, null);
}

// It working in my class SupporterService extends AccessibilityService.

like image 132
Vừng Nhỏ Avatar answered Oct 18 '25 08:10

Vừng Nhỏ


You can not perform any action by position on the screen, you can only do on the nodes, but you can find which node is on your coordinates by recursively checking nodes position-on-the-screen with getBoundsInScreen.

It wouldn't work if it is OpenGL game, and you won't be able to perform the click on the precise location only on the node you found on that location.

like image 22
Nikola Minoski Avatar answered Oct 18 '25 08:10

Nikola Minoski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!