1
votes

Is there any data limit for android push notification GCM using php. I passed data (message) through this code.

 $url = 'https://android.googleapis.com/gcm/send';
    $fields = array (
    registration_ids' => $registatoin_ids,
    data => $message,
        );
     $headers = array(
     Authorization: key= . GOOGLE_API_KEY,
     Content-Type: application/json
      );
     // Open connection
    if(!function_exists('curl_init')) 
     echo "CURL not installed";
    else
     $ch = curl_init();
    // Set the url, number of POST vars, POST data
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // Disabling SSL Certificate support temporarly
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    // Execute post
    $result = curl_exec($ch);
    if ($result === FALSE) {
     die('Curl failed: ' . curl_error($ch));
     }
    // Close connection
    curl_close($ch);
    $obj = json_decode($result);
    if($obj->{'success'})
         {
           echo "Message Sent Successfully";
         }
         else{
          echo "Sending Error : " . $result;
         }

If $message contains more than 3000 characters, then i am not getting any notifications. Suppose if $message contains less than 1000 characters, i got notifications.

Thanks in advance.

1
A notification is a small piece of information. Using GCM, maximum 4kb of payload can be sent in a notification.Dinesh
So, if we send more than 4 kb of payload, it wont work right.Seetha

1 Answers

2
votes

yes It has a payload limit of 4096 bytes.