-1

I have developed an application were on 2 times click on power button triggers SMS API to send SMS to users every 2 mins. I'm using Intent.ACTION_SCREEN_OFF and Intent.ACTION_SCREEN_ON to achieve above mentioned functionality. The issue is the event trigger not only on power button press event but also on other events where the screen gets on and off once, eg. if a message is received and the phone is on lock mode. Please help me with this. Thanks.

Ravindra Kushwaha
  • 7,846
  • 14
  • 53
  • 103
Manish
  • 76
  • 1
  • 1
  • 8
  • Have looked this : http://stackoverflow.com/questions/23559479/android-power-button-press-not-receiving-by-receiver – AndRSoid Dec 24 '15 at 07:51

1 Answers1

1

By this you can find that Power Button is clicked:

public boolean onKeyDown(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_POWER) {
    // do what you want with the power button
    return true;
}
return super.onKeyDown(keyCode, event);
}
santoXme
  • 802
  • 5
  • 20
  • Thanks for your reply. But how can I call it in a background service. As I've handled the above mentioned functionality in an background service so that it can be call event if the application is not running. Can you please check and help me with that. – Manish Dec 24 '15 at 09:57