Description
When Android application is in Background or is not running it is not possibile to send BadgeCount properly.
Android is not receiving the notification with public void onMessageReceived(RemoteMessage message) method so the notification only displays message and title in the bar and notifications page.
When App is in Background, the onMessageReceived is called only when all the push notification informations are sent using the data object but the following code. So if you have to send a PushNotification with title, body and badge you have to send the following payload:
{
"data": {
"title": "sample title",
"body": "sample body",
"count": 4
}
}
But the following code:
if cloud_type == "FCM" and use_fcm_notifications:
notification_payload = {}
if "message" in data:
notification_payload["body"] = data.pop("message", None)
for key in FCM_NOTIFICATIONS_PAYLOAD_KEYS:
value_from_extra = data.pop(key, None)
if value_from_extra:
notification_payload[key] = value_from_extra
value_from_kwargs = kwargs.pop(key, None)
if value_from_kwargs:
notification_payload[key] = value_from_kwargs
if notification_payload:
payload["notification"] = notification_payload
discards the body and title fields and set them in the "notification" object. This results in a simple <Title, message> notification and no badge count is processed.
The right behaviour should be to not change the payload content in order to send all data to the onMessageReceived method. Another choise could be to move the fields from "notification" field in "data" field when a payload or badge is specified.