I am macking a custom navigation bar to Android 4.0.3.r1 and want to send key events like "Home" and "Back". My application is not a system therefore:
IWindowManager mWindowManager = IWindowManager.Stub.asInterface(
ServiceManager.getService(Context.WINDOW_SERVICE));
mWindowManager.injectKeyEvent( ev, false );
It doesn't work, because I can not get android.permission.INJECT_EVENTS
from not system application. How can I do this?
Here are some precision to Roman answer
BaseInputConnection mInputConnection = new BaseInputConnection( findViewById(R.id.main_content), true);
KeyEvent kd = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MENU);
KeyEvent ku = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MENU);
mInputConnection.sendKeyEvent(kd);
mInputConnection.sendKeyEvent(ku);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With