How to determine when the screen is on?

As mentioned in the previous question, it is difficult for me to intercept all events android.intent.action.SCREEN_ONwithout a long-term Service(discouraged).

Perhaps I can get around this problem if I can just work when the screen is on at any given time Service.

Can someone suggest calling a method that will return this information? 1.5 up.

+5
source share
4 answers

The system deliberately does not allow applications to receive ACTION_SCREEN_ONand ACTION_SCREEN_OFFbroadcast in its manifesto, because we really do not want to run a bunch of apps for turning on and off the screen. This is what happens all the time and should be as fast as possible.

, , , .

+1

PowerManager.isScreenOn() : API 7

+5
+3

, , . , AlarmManager.

, ACTION_SCREEN_ON , , , .

If you can work with Android 2.1 and later, PowerManagernow has a method isScreenOn(). The good news is what is available. The bad news is that since it has been added, it is unlikely that there is another way to easily identify it. And, a quick check of the source code does not give much hope that you can hack your way to information in previous SDKs.

+3
source

All Articles