androidandroid-permissionsrootkeyevent

Sending key events (INJECT) in my Android app without root access


I'm working on an Android app that needs to send key events (simulate keyboard input) using the INJECT permission. However, when trying to do so, I receive an error indicating that my app doesn't have the required permissions to inject key events.

Here’s the situation:

I want to send key events programmatically within my app, but I don’t have root access, and my app doesn't have system-level privileges. I’ve tried using android.permission.INJECT_EVENTS and INJECT_KEY_EVENT, but these permissions are restricted and cannot be granted to normal apps. Does anyone know if there's a workaround or a way to grant the necessary permissions without rooting the device? Any suggestions would be appreciated!

Thanks a lot in advance!

I tried using the INJECT_EVENTS and INJECT_KEY_EVENT permissions to send key events programmatically in my Android app. I added the permissions to the AndroidManifest.xml and attempted to simulate key presses through the Instrumentation class.

What I expected:

I expected the app to be able to send key events successfully to simulate user input without requiring root access.

I'm working on custom Google TV remote app to control the tv. In fact, the whole project concerns a robot which got a projector.

What actually happened:

Instead of successfully sending the key events, I received an error indicating that my app doesn’t have the necessary permissions to inject key events. It seems that INJECT_EVENTS and INJECT_KEY_EVENT are restricted permissions that cannot be granted to normal apps, and I'm unable to bypass this restriction without root access.


Solution

  • Being a normal app (non-system app) you are extremely limited in what you can do.

    With an accessibility service there are only a few global actions you can take such as back and home along with a couple of other items none of which will really help with what you want. If he device were on Android 13+ you could use actions such as GLOBAL_ACTION_DPAD_UP, GLOBAL_ACTION_DPAD_DOWN, GLOBAL_ACTION_DPAD_LEFT, GLOBAL_ACTION_DPAD_RIGHT, GLOBAL_ACTION_DPAD_CENTER for navigation but again being on 12 this wont help you.

    If you want full access to inject every event possible then you need your app to be rooted or a system app