Android: Listen for power key press

前端 未结 3 797
一生所求
一生所求 2020-12-03 13:20

I am currently trying to listen for when the power button is pressed. Ultimately I would like to have some code run when the power button is pressed twice, to check whether

3条回答
  •  难免孤独
    2020-12-03 13:24

    I've used android-annotations "@Receiver" annotation.

    Add this to your "@EActivity" annotated Activity:

    @Receiver(actions = Intent.ACTION_SCREEN_OFF)
    protected void onPowerButtonPressed() {
    // add your code
    }
    

提交回复
热议问题