I have migrated my project from using GCM to use Firebase. Push notification comes through ok when the device is awake or been asleep recently but if I leave the device for
It looks like it is not possible to make high priority while sending only data field without notification. Here is the quote from documentation:
High priority messages generally should result in user interaction with your app or its notifications. If FCM detects a pattern in which they don't, your messages may be de-prioritized.
After struggling with a similar issue I managed to get it to work.
I send following json data through postman:
{
"data": {
"body": "Test body from curl"
},
"registration_ids": ["Token"],
"webpush": {
"headers": {
"Urgency": "high"
}
},
"android": {
"priority": "high"
},
"priority": 10
}
It seems like the last "priority":10
is what's fixing it for me.
I could not find any reference to this in the Firebase documentation, but in the deprecated GCM documentation it's used. https://developers.google.com/cloud-messaging/concept-options
While working on an application, I am also stuck at this point. Then I found a issue about it on Github, which solved my problem. That is,
On devices running Android 6.0+, Doze mode terminates all background connections when the phone is idle and not being charged, including the background connection to Pushy.
As soon as the device is moved or awoken by the user, background connections are restored and any pending notifications will be delivered within seconds, providing they have not expired yet.
To send notifications to devices in Doze mode, your app can declare the
REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
permission in itsAndroidManifest.xml
and display a system dialog that asks users to whitelist your app from battery optimizations without leaving the app.This will effectively keep the background connection to Pushy active and devices will be able to receive notifications even in Doze mode.
You can check this issue here https://github.com/ToothlessGear/node-gcm/issues/231
Hope it helps you!
Instead of using "android":{"priority":"high"}, use like this
{
"time_to_live": 300000,
"delay_while_idle": false,
"data": {
"message": "PING_DEVICE",
"time": "21/01/2018 16:20:28",
"pushguid": "10062"
},
"priority": "high"
}
TL;DR - make sure to set the notification priority correctly based on the JSON payload structure for FCM's legacy HTTP protocol vs its HTTP v1 protocol.
There may already be sufficient answers from posts above based on your circumstance or implementation, but I wanted to provide an answer with more context based on the distinction between the legacy HTTP and HTTP v1 protocols that FCM provides in their documentation, but there is a subtle difference between the two protocol APIs when setting notification priority.
Our team experienced the same problem of not receiving push notifications on Android 6+ devices that have Doze enabled even though our server was seemingly setting the priority correctly in the FCM API payload that similar to the payload provided in the original question. We rely on Amazon SNS to forward payloads to FCM, and the payload sent from our server to Amazon SNS would set the priority based on the AndroidConfig JSON object:
{
"android": {
"priority": "high"
}
}
However, this is only correct according to the HTTP v1 protocol. What we didn't realize is that Amazon SNS is likely still using the legacy HTTP protocol where the priority has to be set at the top-level of the JSON payload:
{
"priority": "high", // legacy HTTP protocol (this can also be set to 10)
"android": {
"priority": "high" // HTTP v1 protocol
}
}
Thus, the notification priority would only take effect and enable push notifications to be received while in Doze when the legacy HTTP priority parameter was set to "high" or 10.
For context, these are the API endpoints for each protocol when sending messages to FCM:
"priority"
param (see here)"android"
object with "priority"
param (see here)Thanks for the replies everyone. we finally sorted it.
We logged into the firebase console and realized due to the age of the code we did not use a settings/config file that is generated in the console. sorry i've forgotten the name of it. this file has settings etc which are used when pushes are sent to google. once we used the file in our requests, my application can wake up a phone in doze.
thanks