I'm trying to push some high-priority data messages from a nodejs backend to the android client. Here is my code,
var payload = {
data
};
var options = {
priority: "high",
timeToLive: 0,
ttl: 0,
android: {
priority: "high",
timeToLive: 0,
ttl: 0,
},
};
admin.messaging()
.sendToDevice(deviceFcmId, payload, options)
.then(function (response) {})
.catch(function (response) {
console.error("error sendNotification", response);
});
As you can see, I'm using priority "high" and timeToLive: 0. But this does not wake up the device if it is in Doze mode, or sometimes even if the device is in an unlocked state, the message is delayed up to a few minutes. This is a voice-calling app, so the delivery delay should be minimal. I've searched similar posts on StackOverflow but nothing works for me. What am I missing here? Thanks in advance.
UPDATE:
In my app, there are two types of notifications, Chat notifications and Call notifications. When the user receives a chat notification, the app will write a Realm database entry and fetch the sender's profile picture from API, and shows the notification. I know it's a network call, but the thing is, the image fetching is managed by Glide so 90% of the time it will be a disk cache read rather than a network call (even the network call has a 1-second timeout, after this timeout, it will return a local image).
When the user receives a call notification, the app will start a service and ping the caller using socket.io. If the ping is a success it will show the call screen using a fullscreen intent by calling startForeground from the service. If the ping fails it will show a miscall notification and stops the service.
So, no matter whichever the case is there will always be a user-facing notification.