GCM / FCM notification payload size

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?

+11
source share
6 answers

FCM.

, "" "", 4096 ( ).

, "" "", , "" "", 4062 . , 34 .

, , "" 2 , . 4.

, FCM, , :

. , -. . 4 , Firebase, 1024 .

, "MessageTooBig" :

, , , FCM: 4096 2048 . , .

, , , , , 2.

4 ( , ).

+17

, GCM : . - 2 . 4 /. , , .

- GCM . . . . .

. . /. . , .

+2

, , GCM-.

-API. GCM-, . GCM, .

: Google , GCM.

, Redis - .

+1

4 .

7kb, erroe , , .

, , google .

0

String . , JSON, / :

{
  "to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
  "notification" : {
    "body" : "great match!",
    "title" : "Portugal vs. Denmark"
  }
}

Google:

, :

String mydata = "value from JSON";
byte[] mybyte = mydata.getBytes("UTF-8");
int bytes = mybyte.length;

, String, String. UTF-8.

kB, 1024. .

0

FCM gcm.notification. .

:

  "to":"cgOtBDOGIEc:APA91bGrjdPtrnGr0sIl4c66Z3Xp-JTzUasIN5TzWy7DtNUf-BlGvF64iNOXFN68zFC6oTYHJbP6eQgzIZICcsmIUG-NP5cIXf8EyPNiIAvOFU27XDKFbI2vowMjsNmZQdmh",


  "notification":{
    "title":"Testing title from postman!",
    "body":"Testing body from postman!",
    "sound":"default",
    "tickerText":"This is ticker text"
  },
  "data" : {
     "Nick" : "Mario Test",
     "body" : "great match!",
     "Room" : "PortugalVSDenmark"
   }
}

,

= ( + )

= [ + ] = [Nick + body + Room] + [Mario Test + great match + PortugalVSDenmark] = 12 + 39 = 51

gcm.notification.

firebase gcm.notification. , .

Length of Notification Payload  =  [ no.of keys * length of (gcm.notification.)  +  length of keys + length of values ] 

                                 = 4*17 + length of bytes of [ title + body + sound + tickerText ] + length of bytes of [ Testing title from postman! + Testing body from postman! + default + This is ticker text ]

                                                   = 68 + 24 +79

                                                   =  171 bytes

Total length of the payload = 51 + 171 =  222 bytes.                        

, .

0

All Articles