Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FCM and payload. #574

Open
vlmax74 opened this issue Apr 27, 2020 · 1 comment
Open

FCM and payload. #574

vlmax74 opened this issue Apr 27, 2020 · 1 comment
Labels

Comments

@vlmax74
Copy link

vlmax74 commented Apr 27, 2020

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.

@PhilippDax
Copy link

This is also an issue if you work with phonegap.
https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/PAYLOAD.md#notification-vs-data-payloads
Here you don't want to have the "notification" field and instead only use the "data" field.

@azmeuk azmeuk added the gcm/fcm label Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants