0

I tried to call touch event programatically but not working

fun callTouchEvent(x: Long, y: Long) {
        val e = MotionEvent.obtain(
            SystemClock.uptimeMillis(),
            SystemClock.uptimeMillis(),
            MotionEvent.ACTION_DOWN,
            x.toFloat(),
            y.toFloat(),
            0
        )
        onTouchEvent(e)
    }

Could anyone please help,

how to trigger touch event programatically if we pass co-ordinates parameter to touch event?

Twisha Kotecha
  • 1,082
  • 1
  • 4
  • 18
  • Does this answer your question - https://stackoverflow.com/questions/18059860/manually-trigger-touch-event – Niki Dec 11 '19 at 08:15
  • Does this answer your question? [manually trigger touch event](https://stackoverflow.com/questions/18059860/manually-trigger-touch-event) – Niki Dec 11 '19 at 08:15
  • You can refer to this answer: [https://stackoverflow.com/a/23902985](https://stackoverflow.com/a/23902985) – jeevan deep singh Dec 11 '19 at 09:40

1 Answers1

0

You can not call touch event programatically if application is not handled by you. If it is your application you can call view.dispatchTouchEvent(motionEvent); or view.performClick();

Abdullah Tellioglu
  • 1,434
  • 1
  • 10
  • 26