I'm programming on an Android Set-Top-Box, so I also have to implement onKey Events for the delivered remote control.
My Problem is, that I'm creating a new PopupMenu and then want to dismiss it by certain keyEvents. In fact it should always dismiss, when the user hit other keys than (Up/Down). At the moment it only disapears when the Back Button or an item are pressed. When I'm touching outside the Popupmenu it also disapears. But I need to be able to dismiss the Menu when I'm hitting for example the Key KeyEvent.KEYCODE_2.
The main problem is, that I'm not able to catch ANY onKeyDown/Up etc. events at all!! It simply don't catch any KeyEvent in my Activity when the Popupmenu is showing.
Is there any possibility in catching key events when in Popupmenu/ContextMenu mode?
EDIT: Here is an example how my onKeyDown catch in the MainActivity looks like:
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.e("Key hit","true");
try {
switch (keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
Log.e("Test"," catch left");
return true;
case KeyEvent.KEYCODE_0:
Log.e("Test","hit 0");
break;
case KeyEvent.KEYCODE_2:
Log.e("Test","hit 2");
break;
} catch (Exception e) {
Log.d("onKeyDown", "exception");
e.printStackTrace();
}
return false;
}