Is it possible to touch event on screen programmatically without rooting the device?

761 Views Asked by At

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?

1

There are 1 best solutions below

0
Abdullah Tellioglu On

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();