user1765253
user1765253

Reputation: 33

To make application continue to run when power button is pressed

Hi i have a push to talk application. My application does not continue to run when i press the power button and lock the screen. I am using wake lock with the flag PARTIAL_WAKE_LOCK. How can i provide my application to get voice messages when the user presses the power button.

Upvotes: 0

Views: 147

Answers (1)

Virag Brahme
Virag Brahme

Reputation: 2062

You can get the event of keypress of Power button

@Override
public boolean dispatchKeyEvent(KeyEvent event) 
{
    if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) 
    {
      // Write your logic
      return true;
    }
  return super.dispatchKeyEvent(event);
}  

Hope this will help you..

Upvotes: 2

Related Questions