While waiting for someone to reply to this question, I've discovered the solution myself.
Basically you just need to Override onKeyDown() or onKeyUp() method in related Activity class, and don't forget to return super.onKeyDown() or super.onKeyUp() so unattended KeyEvent will be attended as normally it will.
As for my case, I'm trying to have custom features for channel up & down buttons only. So below is the sample code.
@Override public boolean onKeyDown(int KeyCode, KeyEvent event){ boolean handled = false; if(KeyCode == KeyEvent.KEYCODE_CHANNEL_DOWN){ Log.i("KeyEvent","Channel down button pressed");//for debugging, to be printed on logcat handled=true; //do something } else if(KeyCode == KeyEvent.KEYCODE_CHANNEL_UP){ Log.i("KeyEvent","Channel up button pressed");//for debugging, to be printed on logcat handled=true; //do something } if(handled){ return handled; } //return super.onKeyDown() to attend unattended KeyEvent else{ return super.onKeyDown(KeyCode, event); } }
KeyEvent class documentation that contains list of KEYCODE constants available can be found here.