5

I´m new to android development and I´m trying to make an app.
What I want to know is if is it possible to get key events even when the phone is locked?

For example to make my music player change the music when I press the DPAD_CENTER_BUTTON

Doing something like this:

@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) {

    switch (keyCode) {
        case KeyEvent.KEYCODE_ENTER:
        {
            //your Action code
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

Is that possible?

Mat
  • 202,337
  • 40
  • 393
  • 406
Guilherme Gusman
  • 556
  • 2
  • 7
  • 17

1 Answers1

0

You can use a broadcast receiver for the Intent Filter Intent.ACTION_SCREEN_OFF

Abhishek Nandi
  • 4,265
  • 1
  • 30
  • 43