0
I have an Accessibility service that captures events touch the screen, and I have a USB mouse connected to the Android device, I would like to know how I can recover the mouse position on the screen, or be notified when the mouse change its position.
found setOnCapturedPointerListener, but it is API LVL 26, accurate in API 24.
myView.setOnCapturedPointerListener(new View.OnCapturedPointerListener() {
@Override
public boolean onCapturedPointer (View view, MotionEvent motionEvent) {
// Get the coordinates required by your app
float horizontalOffset = motionEvent.getX();
// Use the coordinates to update your view and return true if the event was
// successfully processed
return true;
}
});
found myView.setOnCapturedPointerListener(new View.Oncapturedpointerlistener() { @Override public Boolean onCapturedPointer (View, Motionevent motionEvent) { // Get the coordinates required by your app float horizontalOffset = motionEvent.getx(); // Use the coordinates to update your view and Return true if the Event was // successfully processed Return true; } }); but does not work in API 24.
– Victor Costa
Please do not add "Solved" to the title. I know it is common practice in many forums, but here it works different. In case, you can answer for yourself, just add an answer below (in the "Your Answer" field). Then, enough accept the answer, that the site itself will already indicate that the problem is solved
– hkotsubo