Simulating touches onto an activity of another app

2019-06-04 01:01发布

问题:

Is it possible to simulate touch events in Android from one app to another app? Perhaps use a service or an invisible activity with SYSTEM_ALERT property to receive the input touches then simulate them to another activity of another application which is directly below the transparent activity of your application. Is this possible?

[UPDATE]

Taking FoamyGuy's answer into account, is it possible to have an invisible SYSTEM_ALERT activity to filter out certain touch events? I know you can revoke input for the activity. Is it possible to revoke selective input? Or do I still have to create a custom ROM?

回答1:

Yes it is, if your app is signed with the platform certificate you may use the INJECT_EVENTS permission and inject events on any application:

http://developer.android.com/reference/android/Manifest.permission.html#INJECT_EVENTS



回答2:

It is not possible. This would be cause for major security concern. You can use the Instrumentation APIs to inject events into your own Activities, but you cannot inject events into any Activities that are not your own.

The ability to do so would make it trivial to circumvent the necessity for user interaction to do certain things (i.e. install/uninstall apps).

If you want to be able to do it you'll have to modify the system on your own device to enable it.