GCM (or data) limitation

I have php code to send push notifications. It works for small data (messages), but when I try to send a large String in a push notification, it does not work. Is there a line limit for sending to GCM? if any size?

Thanks at adavnce

+1
source share
2 answers

Yes, there is a limit of 4096 bytes in the message payload (including all user keys and values ​​in your payload).

+3
source

, 2048 . , UTF-8 , , , . .

// Prepare JSON containing the GCM message content.
JSONObject jGcmData = new JSONObject();
jGcmData.put("to", "/topics/"+args[0].trim());
// Set maximum time alive in seconds.
jGcmData.put("time_to_live", 300);
// Set the collapse key, which groups as one the messages of same topic
jGcmData.put("collapse_key", args[0].trim());
// Prepare the GCM data
JSONObject jData = new JSONObject();
String message = readFile(args[1].trim(), Charset.forName("UTF-8"));
jData.put("message", message);
System.out.println("Data length: " + message.length());
// Add the data to the message.
jGcmData.put("data", jData);
System.out.println("Total GCM length: " + jGcmData.toString().getBytes("UTF-8").length);
// Create connection to send GCM Message request.
URL url = new URL("https://android.googleapis.com/gcm/send");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "key=" + API_KEY);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestMethod("POST");
conn.setDoOutput(true);
 // Send GCM message content.
DataOutputStream outputStream = new DataOutputStream(conn.getOutputStream());
outputStream.write(jGcmData.toString().getBytes("UTF-8"));
outputStream.flush();
outputStream.close();
// Read GCM response.
InputStream inputStream = conn.getInputStream();
String resp = IOUtils.toString(inputStream);
System.out.println(resp);
System.out.println("SUCCESS!");
0

All Articles