I'm developing an app that need to make changes in database when server data changes. Now I'm using Firebase Cloud Message notifications to update the data. But how can I update the app if the payload size > 4 Kb.
2 Answers
If you attempt to send a payload that is beyond the size limit, you'll receive the MessageTooBig error:
Check that the total size of the payload data included in a message does not exceed FCM limits: 4096 bytes for most messages, or 2048 bytes in the case of messages to topics or notification messages on iOS. This includes both the keys and the values.
What you can do depends on the contents of the payload you're planning to send. Usually, I would suggest to make use of a database (Firebase Database perhaps?) to store the big data and the only thing you need to send in the FCM payload is a URI of some sort or an action on what the app should do.
The way I understand push notification is that the data being sent in the payload should not be app critical, as mentioned in the comment of @ArthurThompson here:
So when sending notification messages to Android, the accompanying data should be data that is enhancing the notification experience. It should not be app critical data, use data messages for data that the application needs even if the user dismisses the notification.
-
Thanks, how can I repeatedly make API call in background if the initial request fails for some reasons . Another thing is if multiple push notifications arrives at once like a user not connected to network for a long time, then how can i make the API calls without effecting apps performance. What are the techniques used to handle these situation – rajeev kumar Nov 18 '16 at 11:57
-
@rajeevkumar That's a lot of follow up and a bit broad to answer. I suggest posting a separate question, making it specific as possible – AL. Nov 19 '16 at 04:07
The best practice in such cases is to avoid sending the whole payload through the push message.
Instead, you should send only the data needed to identify the changed data and make the app request the updates directly from the server.

- 768
- 4
- 10
-
Thanks, how can I repeatedly make API call in background if the initial request fails for some reasons . Another thing is if multiple push notifications arrives at once like a user not connected to network for a long time, then how can i make the API calls without effecting apps performance – rajeev kumar Nov 18 '16 at 11:46
-
You should see how to send collapsible messages for when the same data changes again [link](https://developers.google.com/cloud-messaging/concept-options) – BMacedo Nov 18 '16 at 15:27
-
Also, the [GcmNetworkManager](https://developers.google.com/cloud-messaging/network-manager) might be useful for your use case – BMacedo Nov 18 '16 at 15:29