Android IR Remote Override Power Key

496 Views Asked by At

How to Override the power key of an IR remote for a rooted Android device? I have tried the following

         case KeyEvent.KEYCODE_STB_POWER:
            Toast.makeText(this, "KEYCODE_STB_POWER key pressed",
                    Toast.LENGTH_SHORT).show();
            return true;

        case KeyEvent.KEYCODE_AVR_POWER:
            Toast.makeText(this, "KEYCODE_AVR_POWER key pressed",
                    Toast.LENGTH_SHORT).show();
            return true;

        case KeyEvent.KEYCODE_TV_POWER:
            Toast.makeText(this, "KEYCODE_AVR_POWER key pressed",
                    Toast.LENGTH_SHORT).show();
            return true;

        case KeyEvent.KEYCODE_POWER:
            Toast.makeText(this, "KEYCODE_POWER key pressed",
                    Toast.LENGTH_SHORT).show();
            return true;

But none of the above worked. Am I missing anything?

1

There are 1 best solutions below

0
Neron T On

Try logging the key so you get the actual KeyEvent to be treated. for example:

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    Log.d("keycode", "" + keyCode);
(...)
}