Is it possible to detect when screen will turn off and catch it? I want to set timer for 15 seconds in global settings of Android. I am trying to find some information how to catch wake-lock mode.
Asked
Active
Viewed 2,841 times
2
-
http://stackoverflow.com/questions/17947126/how-do-i-detect-when-android-device-screen-is-about-to-timeout-or-lock – A Honey Bustard Oct 27 '16 at 13:37
-
Take a look at [Keeping the Device Awake](https://developer.android.com/training/scheduling/wakelock.html#screen). – Bryan Oct 27 '16 at 13:38
1 Answers
2
Just register your app for the actions Intent.ACTION_SCREEN_OFF
and Intent.ACTION_SCREEN_ON
and do what you want when these events are broadcasted.
Create a dedicated BroadcastReceiver
class (and add it to the manifest) or register a BroadcastReceiver
at runtime.

Massimo
- 3,436
- 4
- 40
- 68
-
2According to [this answer](http://stackoverflow.com/a/11350278/56285), you cannot declare `ACTION_SCREEN_ON` and `ACTION_SCREEN_OFF` in AndroidManifest; you need to do it in code – Jonik May 08 '17 at 13:00
-
-
@Jonik Thanks! it was like a quest. From your link I went Stack, then to another comment, then to another site :) Finally: https://thinkandroid.wordpress.com/2010/01/24/handling-screen-off-and-screen-on-intents/ – Vit Jun 29 '23 at 16:02