ANDROID. Emulate Hardware Keys with an IME. Doesn't work with Dialog and Spinner
- by shutdown11
I have understand that the only way to inject KeyEvents in the Android System is to implement an Input Method.
I have created my IME with the purpose to control from remote the device.
I emulate the hardware keys using the method
private void keyDownUp(int keyEventCode) {
getCurrentInputConnection().sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_DOWN, keyEventCode));
getCurrentInputConnection().sendKeyEvent(
new KeyEvent(KeyEvent.ACTION_UP, keyEventCode));
}
in my class that extends InputMethodService.
It works fine until an AlertDialog, or the menu of a Spinner comes in foreground. Also the windows that appears when the Menu key is problematic.
My IME can't get focus on them, and the keyevents are sent to the activity behind them.
Using hardware keys, the Dialog get the focus and you can select the botton on the Dialog.
How can i emulate that, using the IME(or anything else)?