如何找出屏幕状态在Android设备上? [英] how to find out screen status on an android device?

查看:159
本文介绍了如何找出屏幕状态在Android设备上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法找出Android设备屏幕上或没有广播接收器?我想就通过服务,由管理员报警器调用分钟间隔更新。我也想preserve电池寿命。所以,如果设备屏幕上的更新服务将运行。

我发现了一个解决我的问题与此code:

  PowerManager的电源管理;
电源管理=(电源管理)this.getSystemService(Context.POWER_SERVICE);
如果(powermanager.isScreenOn())
    {
        ...
    }


解决方案

您可以考虑另一种解决问题的方法:

使用广播接收器,当屏幕开启设置重复报警。然后,当屏幕关闭时,取消报警。

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

解决方案

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.

这篇关于如何找出屏幕状态在Android设备上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆