ANDROID. Emulate Hardware Keys with an IME. Doesn't work with Dialog and Spinner
Posted
by shutdown11
on Stack Overflow
See other posts from Stack Overflow
or by shutdown11
Published on 2010-05-10T19:50:08Z
Indexed on
2010/05/10
19:54 UTC
Read the original article
Hit count: 255
android
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)?
© Stack Overflow or respective owner