slash33
slash33

Reputation: 899

Send touch screen event to foreground activity (only from APK)

I am trying to send touch events (clicks and motions) to the foreground application from an application with system privileges (standard upload, not rooted)

I was able to run shell scripts emulating the inputs directly from linux shell but not from my application:

Runtime.getRuntime().exec(cmd)

returns

cannot open /dev/input/event1, permission denied

This occurs if cmd is sh /path/script-emulating-events or sendevent /dev/input/event1 xxxx x x.

Since the application has android.uid.system for shared user id, it shouldn't be an android privilege issue.

Any idea?

Upvotes: 1

Views: 1960

Answers (2)

slash33
slash33

Reputation: 899

There appears to be something new in Jelly Bean! The input commands have improved:

usage: input ...
       input text <string>
       input keyevent <key code number or name>
->       input tap <x> <y>
->       input swipe <x1> <y1> <x2> <y2>

It worked fine on 4.1.2

Upvotes: 0

Wei Liu
Wei Liu

Reputation: 575

In order to run those commands, you have to root your device.

Upvotes: 1

Related Questions