打ze模式处理 [英] Doze mode handling

查看:171
本文介绍了打ze模式处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用AlarmManager在后台生成一些服务的应用程序.时间对于我们的应用程序至关重要,其功能不能等待下一个维护窗口的出现. 要求用户将应用程序列入白名单不是问题,但不能解决暂停警报的问题.同样,电池消耗也不是什么大问题.

我想到的第一个可能的解决方案是生成一个始终运行的前台服务来处理服务的重新安排,而不是使用AlarmManager来处理,但是这样做会改变我们应用程序的大多数基本结构,因此对我们来说是不可行的./p>

我刚刚实现的当前解决方法是发送高优先级的推送通知,并在接收到消息后采取完全唤醒锁定并打开屏幕以中断打do模式.

我想知道是否还有另一种打破打ze模式的方式?也可以不使用唤醒锁吗?实施上述解决方案可能会产生一些影响吗?

P.S.我正在使用UrbanAirship进行推送通知.

解决方案

您无法中断"/停止/禁用打ze模式,但是有一些方法可以在设备打zing睡时暂时解除应用程序的限制.

  1. 高优先级FCM消息.

FCM高优先级消息使您可以可靠地唤醒应用程序以访问网络,即使用户的设备处于打ze状态或应用程序处于待机模式也是如此.在打ze"或应用程序待机"模式下,系统会传递消息并为应用程序提供对网络服务和部分唤醒锁的临时访问权,然后将设备或应用程序返回到空闲状态.

高优先级FCM消息不会影响打ze"模式,也不会影响任何其他应用程序的状态.这意味着您的应用程序可以使用它们进行有效的通信,同时将对整个系统和设备的电池影响降到最低.

  1. 使用AlarmManager设置的andAllowWhileIdle警报.

打ze特别可能会影响AlarmManager警报和计时器管理的活动,因为当系统处于打ze状态时,Android 5.1(API级别22)或更低版本的警报不会触发.

为了帮助安排警报,Android 6.0(API级别23)引入了两个新的AlarmManager方法:setAndAllowWhileIdle()和setExactAndAllowWhileIdle().使用这些方法,您可以设置即使设备处于打ze状态也将触发的警报.

请注意,在打ze模式下两次报警之间的最小间隔为9分钟.


对于这两种情况,您的应用都将在短时间内恢复到全部功能(这意味着:睡限制不适用),当该时间到期时,操作系统将恢复the睡限制.

请注意,在这两个唤醒"时间段中,您都无需打开屏幕即可执行代码.

我手头没有消息来源,但我相信我所说的很短时间是10秒.

来源&额外阅读

I am working on an application which spawns some services in the background using AlarmManager. Timing is very crucial to our application and the functionality can't wait for the next maintenance window to occur. Asking a user to white-list the application is not an issue but doesn't fix the issue of suspending alarms. Also battery consumption is not that big of an issue as well.

First possible solution that came to my mind was to spawn an always running foreground service to handle the rescheduling of services instead of AlarmManager but in doing so will shift most of the base structure of our application and is not feasible for us.

Current fix that I just implemented is to send a high priority push notification and on receiving the message, take full wake lock and turn on the screen to break doze mode.

I wanted to know if there is an alternate way of breaking doze mode? Also is it possible without taking a wake lock? Can there be some possible repercussions of implementing the aforementioned solution?

P.S. I am using UrbanAirship for push notifications.

解决方案

You can not "break"/stop/disable doze mode, but there are ways to temporarily lift your app's restrictions while the device is dozing.

  1. A high priority FCM message.

FCM high-priority messages let you reliably wake your app to access the network, even if the user’s device is in Doze or the app is in App Standby mode. In Doze or App Standby mode, the system delivers the message and gives the app temporary access to network services and partial wakelocks, then returns the device or app to the idle state.

High-priority FCM messages do not otherwise affect Doze mode, and they don’t affect the state of any other app. This means that your app can use them to communicate efficiently while minimizing battery impacts across the system and device.

  1. An andAllowWhileIdle alarm set with AlarmManager.

Doze is particularly likely to affect activities that AlarmManager alarms and timers manage, because alarms in Android 5.1 (API level 22) or lower do not fire when the system is in Doze.

To help with scheduling alarms, Android 6.0 (API level 23) introduces two new AlarmManager methods: setAndAllowWhileIdle() and setExactAndAllowWhileIdle(). With these methods, you can set alarms that will fire even if the device is in Doze.

Note that the minimum interval between two alarms in doze mode is 9 minutes.


For both cases, your app is restored to full functionality (meaning: the doze restrictions do not apply) for a short period of time, when that time expires, the OS will reinstate the doze restrictions.

Note that you do not need to turn on the screen to execute code during either of these 'wake up' periods.

I don't have a source at hand, but I believe the short period I name is ~10 seconds.

Source & additional reading

这篇关于打ze模式处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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