title: Send multiple messages with GCM
body: <p>I've been dealing with this issue since 2 days. What I want to do is, I've to send multiple messages to registered GCM device. Till now I can send single message to device. Below is the code to send message.</p>
  
  <h2>send_message.php</h2>
  
  <pre><code>&lt;?php
  
      if (isset($_REQUEST["regId"]) &amp;&amp; isset($_REQUEST["message"])) {
          $regId = $_REQUEST["regId"];
          $message = $_REQUEST["message"];
  
          include_once './GCM.php';
  
          $gcm = new GCM();
  
          $registatoin_ids = array($regId);
          $message = array("price" =&gt; $message);
  
          $result = $gcm-&gt;send_notification($registatoin_ids, $message);
          echo $registatoin_ids; echo $message; 
          echo $result;
  
      }
  </code></pre>
  
  <h2>GCM.php</h2>
  
  <pre><code>&lt;?php
  
  class GCM {
  
      //put your code here
      // constructor
      function __construct() {
  
      }
  
  
      //Sending Push Notification
  
      public function send_notification($registatoin_ids, $message) {
          // include config
          include_once './config.php';
  
  
          // Set POST variables
          $url = 'https://android.googleapis.com/gcm/send';
  
          $fields = array(
              'registration_ids' =&gt; $registatoin_ids,
          'message' =&gt; $message, 
            );
  
  
          $headers = array(
              'Authorization: key=' . GOOGLE_API_KEY,
              'Content-Type: application/json'
          );
  
          //print_r($headers); exit();
          // Open connection
          $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);
          echo $result;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>Here message is being received on receiver side..
  // code for this is in GCM.php</p>
  
  <pre><code> $fields = array(
              'registration_ids' =&gt; $registatoin_ids,
              'message' =&gt; $message, 
            );
  </code></pre>
  
  <p>But I want to send multiple messages in single notification. for that what I did...</p>
  
  <h2>send_message.php</h2>
  
  <pre><code>&lt;?php
  
  
  if (isset($_REQUEST["regId"]) &amp;&amp; isset($_REQUEST["message"]) &amp;&amp; isset($_REQUEST["data"])) {
      $regId = $_REQUEST["regId"];
      $message = $_REQUEST["message"];
      $data = $_REQUEST["data"]; //added third parameter
  
  
      include_once './GCM.php';
  
      $gcm = new GCM();
  
      $registatoin_ids = array($regId);
      $message = array("price" =&gt; $message);
      $data = array("extra" =&gt; $data);
  
  
      $result = $gcm-&gt;send_notification($registatoin_ids, $message, $data);
      echo $registatoin_ids; echo $message; echo $data;
      echo $result;
  }
  </code></pre>
  
  <h2>GCM.php</h2>
  
  <pre><code>&lt;?php
  
  class GCM {
  
      //put your code here
      // constructor
      function __construct() {
  
      }
  
      /**
       * Sending Push Notification
       */
      public function send_notification($registatoin_ids, $message, $data) {
          // include config
          include_once './config.php';
  
  
          // Set POST variables
          $url = 'https://android.googleapis.com/gcm/send';
  
          $fields = array(
              'registration_ids' =&gt; $registatoin_ids,
          'message' =&gt; $message, 
          'data' =&gt; $data,
          );
  
  
          $headers = array(
              'Authorization: key=' . GOOGLE_API_KEY,
              'Content-Type: application/json'
          );
  
          //print_r($headers); exit();
          // Open connection
          $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);
          echo $result;
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>And in android I wrote the function to receive message like this...</p>
  
  <pre><code>@Override
  protected void onMessage(Context context, Intent intent) {
      Log.i(TAG, "Received message");
      String message = intent.getStringExtra("price");
      String newmessage = intent.getStringExtra("extra");
      displayMessage(context, message + newmessage);
      generateNotification(context, message + newmessage);
  }
  </code></pre>
  
  <p>But I'm getting null result for "price" and getting result for "extra".
  How can I receive multiple message string in single notification?</p>