I am trying to simulate a click function in an android application utilizing the Accessibility Service. I have set up the service in the manifest, and enabled it in my phones settings. I have a class MouseAccessibilityService which contains the following click function:
// Click 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();
}
I am calling the click function in the MainActivity via a button press that triggers the click (for testing purposes):
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);
}
});
The X and Y is being passed as an integer variable from some other functionality. I can not seem to get the click() function to work from within my app and press on a button.
Am I on the right page? Can this functionality even work? I am at a standstill with this and would appreciate any help.
Thanks.