how to find out screen status on an android device?

拥有回忆 提交于 2020-01-03 15:22:07

问题


Is there any way to find out that the android device screen is on or not without broadcast receivers? I want to make minute interval updates on device via service that is invoked by alarm manager. I also want to preserve battery life. So the update service will run if the device screen is on.

i found a solution to my problem with this code:

PowerManager powermanager;
powermanager = (PowerManager) this.getSystemService(Context.POWER_SERVICE); 
if (powermanager.isScreenOn())
    {
        ...
    }

回答1:


You can consider another approach to the problem:

Using Broadcast Receivers, set your repeating alarm when the screen is turned on. Then, when the screen is turned off, cancel your alarm.



来源:https://stackoverflow.com/questions/9954630/how-to-find-out-screen-status-on-an-android-device

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!