由网友(淺陌離殇ゝ)分享简介:有没有办法找出Android设备屏幕上或没有广播接收器?我想就通过服务,由管理员报警器调用分钟间隔更新。我也想preserve电池寿命。所以,如果设备屏幕上的更新服务将运行。我发现了一个解决我的问题与此code: PowerManager的电源管理;电源管理=(电源管理)this.getSystemService(C...
有没有办法找出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.
相关推荐
最新文章