This question originally related to Google Cloud Messaging (GCM), but now it also refers to the new Firebase Cloud Messaging (FCM), which replaces GCM.
I would like to know how to calculate the size of the GCM payload when it contains a dictionary of “notifications”.
I tried the Google Cloud Messaging service for Android. Some parts of the documentation say that you can send up to 4 KB of data, but it says: "A notification can have a maximum payload of 2 KB."
By performing some tests, I could send messages with a "data" payload filled with 4 KB of data, and the server received them without errors, as expected.
However, using the “notification” payload, I found that I can send messages with a data size of more than 2 KB, and the server does not return an error. I expected such posts to be too large.
I found that the notification payload shares the allowed 4K with the data payload, but not like that. In the "data" payload, you can calculate the size by adding the size of the keys and values. The notification payload takes up more space than the size of the keys and the values it contains.
How can I pre-calculate the size of the payload if it contains a notification dictionary?
source
share