How to find out the screen status on an Android device?

Is there a way to find out if the screen of an Android device is on or not without broadcast receivers? I want to make updates of minute intervals on the device through a service that is called by the alarm manager. I also want to save battery life. Thus, the update service will be started if the device screen is turned on.

I found a solution to my problem with this code:

PowerManager powermanager;
powermanager = (PowerManager) this.getSystemService(Context.POWER_SERVICE); 
if (powermanager.isScreenOn())
    {
        ...
    }
+5
source share
1 answer

You may consider a different approach to the problem:

Using broadcast receivers, set an alarm when the screen is on. Then, when the screen is off, cancel the alarm.

+1
source

All Articles