Does the payload 4096 bytes include the registrati

2019-04-29 16:08发布

问题:

In the Android GCM document, it is said that the payload is up to 4096 bytes limit.

Does the payload's 4096 bytes include the registration_id length? I found I could send a message with a payload of 16038 bytes (including the registration_ids).

回答1:

It doesn't include the registration ids.

I'm sorry for not supplying any supporting documentation. The GCM documentation doesn't state it clearly. However, I tested it in order to verify this behavior. The only "proof" I can supply is that in a multicast message you can include up to 1000 registration ids. A 1000 registration ids obviously cannot fit into the 4096 bytes of the payload.

From http://developer.android.com/google/gcm/gcm.html :

registration_ids

A string array with the list of devices (registration IDs) receiving the message. It must contain at least 1 and at most 1000 registration IDs. To send a multicast message, you must use JSON. For sending a single message to a single device, you could use a JSON object with just 1 registration id, or plain text (see below). Required.



回答2:

To complete the accepted answer. I have been testing this and the result is as follows:

The max lenght of the payload is 4096 bytes. If you are using JSON, and your message is as follows:

{
  "to" : "APA91bGbkLeRLD228BKYQy4syvAYd5ErYiHup5FzofY_8x5CNHmhMlB65CaCHj9ntm7zcMhzDEkd9vi6rxM89cRzPuDLPrlX8UgYExGQ3LmakGTKpkIS0CE9-9tinlIRLMiLoGKDn5jVvks0njvcGFPJSHBn23cd-A",
  "data": {"a":"Some information. Only this part inside data counts as payload"}
}

The only part of the message that counts as payload is the part inside "data". This is true even if you are sending to multiple devices.

{
  "registration_ids" : ["APA91bGbkLeRLD228BKYQy4syvAYd5ErYiHup5FzofY_8x5CNHmhMlB65CaCHj9ntm7zcMhzDEkd9vi6rxM89cRzPuDLPrlX8UgYExGQ3LmakGTKpkIS0CE9-9tinlIRLMiLoGKDn5jVvks0njvcGFPJSHBn23cd-A",
                        "APA91bGbkLeRLD228BKYQy4syvAYd5ErYiHup5FzofY_8x5CNHmhMlB65CaCHj9ntm7zcMhzDEkd9vi6rxM89cRzPuDLPrlX8UgYExGQ3LmakGTKpkIS0CE9-9tinlIRLMiLoGKDn5jVvks0njvcGFPJSHBn23cd-A"]
  "data": {"a":"Some information. Only this part inside data counts as payload"}
}