Question

I want to know if it is possible to generate automatic touch at regular intervals of time, say 5 seconds in another application. For example..I want to develop an application which will create a touch response just as we touch the screen, at a particular coordinate at regular fixed interval. Please help.

Was it helpful?

Solution

Yes, you can do the same.

root is the root view of your layout, here.

root.dispatchTouchEvent(MotionEvent.obtain(
                SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                MotionEvent.ACTION_DOWN, Xinput, Yinput, 0));

Also, Please check this link, It has several approaches explained with example. http://www.pocketmagic.net/2012/04/injecting-events-programatically-on-android/#.U5Axo_m1ZOI

OTHER TIPS

It's possible to create and dispatch touch events in your application. It's pretty easy. Look at View.dispatchTouchEvent method and parameters. You have to override that method in root view group so you can pass your events to all views in the activity.

It's not possible to access other applications though (due to security reasons).

edit: seems like dispatchTouchEvent is public, so no need to override

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top