-1

So, I need to create a service that listens on a HTTP port for characters and then simulate pressing of that key, so it seems that the user has pressed the key himself, regardless of which application is in the front, and that application should accept it.

Can you do that and how would one do that? Thanks in advance!

edit: i have found this which grants the app, and I qoute "Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window. Without this permission, you can only deliver events to windows in your own process. Very few applications should need to use this permission."

stipetic
  • 41
  • 1
  • 7

1 Answers1

4

No you can't. It would be a severe security hole if you could. The only semi-normal way that anything like that might be possible is for you to implement a soft keyboard, but even then the soft keyboard isn't always open. Short of making changes to the OS or possibly doing something as root, this just shouldn't be possible.

Update:

Yes technically there's INJECT_EVENTS, but that requires you to be a system app. If you're building a ROM or as I mentioned before if you're rooted you could use this, but otherwise you're out of luck.

Community
  • 1
  • 1
kabuko
  • 36,028
  • 10
  • 80
  • 93
  • not even if the application specifically asks for a permission for that, like it has to ask for permission to access the internet and stuff like that? – stipetic Nov 30 '11 at 20:08
  • Nope. There is no such permission for the keyboard. Even with such permissions it'd be fairly dangerous. That's just not included in the API. – kabuko Nov 30 '11 at 20:37
  • I'm sorry for being so pushy, bu please take a look at [this](http://developer.android.com/reference/android/Manifest.permission.html#INJECT_EVENTS), it seems to be exactly what I need – stipetic Nov 30 '11 at 20:40