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:
Will the device be awake long enough for me to download the image and save it to the db (image size is max 100kb)?
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).
来源:https://stackoverflow.com/questions/42272509/how-long-will-the-device-stay-awake-when-it-receives-a-fcm-high-priority-message