简体   繁体   中英

Android Power button click issue

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.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM