开发者

how to handle lock screen button input for android activity?

开发者 https://www.devze.com 2023-01-24 12:29 出处:网络
Suppose I have something like an alarm activity which launches the alarm through the lock screen, accomplished via

Suppose I have something like an alarm activity which launches the alarm through the lock screen, accomplished via

getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

Now, from here I could press the back button to kill the activity, but I also want a press of the lock button to silence the alarm. How would I go about creating a handler for presses of the开发者_运维知识库 lock screen button?


Listen to this broadcast intent

ACTION_SCREEN_OFF

You can switch off your alarm when you get this intent

0

精彩评论

暂无评论...
验证码 换一张
取 消