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())
{
...
}
source
share