5
我正在编写一个Android客户端应用程序,它使用HTTP长轮询(Comet)不断接收来自服务器的推送通知。什么事件可以唤醒睡眠中的Android设备?
我不想永远保持WakeLock,因为它会消耗电池电量,但是我需要确保设备即使在睡眠模式下也能收到通知。
而且我发现这个问题:
Android: Sleep stages/levels on an Android device?
其中“CommonsWare”提到,为非WiFi插座传入数据包会唤醒设备。
所以我的解决办法是这样的:
Client ------------------------- Server
---- Request----->
release WakeLock (Allow device to sleep)
<----Notification-- (Hopes it can wake up the device)
require WakeLock
process the notification
---- Request----->
release WakeLock
....
但有收到通知,并要求激活锁定之间的一个小的时间窗口,所以我的问题是,如何长时间的设备保持这种清醒状态?在这段时间内,设备是否可以恢复睡眠?