设备在收到FCM高优先级消息时会保持多久? [英] How long will the device stay awake when it receives a FCM high priority message?

查看:606
本文介绍了设备在收到FCM高优先级消息时会保持多久?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firebase文档中读到,如果设备收到来自FCM的高优先级消息,并且网络连接将向应用程序服务器打开,则该设备将从睡眠状态中解除。我已经测试了这种行为,我知道它确实唤醒了一个设备打瞌睡。

我的用例是这样的,我需要下载一个图像推送消息的数据标签。将有多个这样的推送通知,我将保存所有这些消息在数据库中。



说了十分钟后,通知将实际触发到用户的屏幕为了避免用户收到的许多其他通知立即打开网络连接。

我的问题实质上是:


  1. 设备是否能够唤醒足够长的时间来下载图像并将其保存到数据库中(图像大小最大为100kb)?

  2. b $ b
  3. 或者应该使用JobScheduler API推迟下载,以确保网络连接?



是的,你应该推迟下载,但这取决于你的应用程序的性质。文档说,高优先级的消息给予应用程序临时访问权限,因此不能保证您的图像下载将在该窗口中实际完成。



您的应用程序消息是否对时间敏感(我的意思是如果用户在10分钟后看到它们,世界就会崩溃)?如果没有,那么你应该完全按照自己的建议。否则,你可能会开始一个前台服务,可能会阻止设备打盹模式(注意你的应用程序可能会耗尽大量的电池,最终这可能会给用户造成负面印象)。

I read in the Firebase docs that a device will be brought out of sleep if it receives a high priority message from FCM and that the network connection will be opened towards the app server. I have tested this behaviour and i know that it does wake a device from doze.

My use case is such that i need to download an image using a set key in the data tag of the push message. There will be multiple such push notifications and i will be saving all these messages in a db.

After say ten minutes, the notifications will actually be triggered onto the user's screen in order to avoid the multitude of other notifications user has received on immediately turning on the network connection.

My question essentially is:

  1. Will the device be awake long enough for me to download the image and save it to the db (image size is max 100kb)?

  2. Or should I instead defer the downloads to a later time using JobScheduler API in order to ensure network connectivity?

解决方案

Yes, you should defer the downloads but that depends on the nature of your app. Docs say that high priority messages give the app temporary access and as such it is not guaranteed that your image download will actually finish in that window.

Are your app message time sensitive (i mean would the world crumble if the user sees them after 10 minutes)? If not then you should exactly follow your own suggestion. Else may be you can start a foreground service which might prevent the device for being going to doze mode (Be aware your app might drain a lot of battery and eventually this might create a negative impression on the user).

这篇关于设备在收到FCM高优先级消息时会保持多久?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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