Firebase Save Notification To Db Not Working When App Is Not Running
Solution 1:
Firebase notifications in Android are not sent to your registered messages service when your app is in background and your notification contains a notification
key. To ensure your service always handles notifications, don't use the notification
field. Instead use the data
field for that purpose.
Actually one downside of using Firebase's notification
field is that you cannot specify a large and small icons for the system tray notification. It only lets you set one icon.
Note however that this is not a "universal" solution since iOS users will not receive a notification in background when there's no notification
field present.
Having said that, I think the best solution right now is to send you Android users a notification like the following:
{
"to":"tHt4D...",
"data":
{
"title":"Nice title",
"body":"Nice body"
}
}
and handle it in your service like this:
publicvoidonMessageReceived(RemoteMessage remoteMessage) {
Map<String, String> data = remoteMessage.getData();
makeMyCustomNotification(data.get("title"), data.get("body"));
}
For iOS users use the standard way:
{
"to":"tHt4D...",
"notification":
{
"title":"Nice title",
"body":"Nice body"
}
}
There's a big discussion around this topic here
Post a Comment for "Firebase Save Notification To Db Not Working When App Is Not Running"