0

I'm trying to emulate touch and swipes on keyboard in my android app, I find a solution how to do it with dispatchTouchEvent(motionEvent e) like in code here, but it doesn't work for me. What is wrong with it, or maybe there is better solution?

void simulateEventDown(Activity yourActivity, long x, long y) {
    MotionEvent e = MotionEvent.obtain( SystemClock.uptimeMillis(),
            SystemClock.uptimeMillis(),
            MotionEvent.ACTION_DOWN,
            x, y, 0);
    yourActivity.dispatchTouchEvent(e);

} My app

wein_wein
  • 1
  • 1
  • 1
    Does this answer your question? [How to simulate a touch event in Android?](https://stackoverflow.com/questions/4396059/how-to-simulate-a-touch-event-in-android) – thibsc May 08 '20 at 22:16
  • seems like no, because keyboard is not a view element from which we can call method, as i googled – wein_wein May 08 '20 at 23:21
  • Out of curiosity: why not just send the IME events? I'd expect that to result in less flaky tests as keyboards change. – Ryan M May 09 '20 at 00:27
  • If you are about key codes, it's not what I'm looking for. I need remote gesture (swipe) input – wein_wein May 09 '20 at 07:24

0 Answers0