title: Android GCM message successfully sent but not received
body: <p>I'm trying to use the GCM service to send push notifications to my devices.</p>
  
  <p>I've followed the <a href="http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/" rel="nofollow noreferrer" title="Android Hive tutorial">Android Hive tutorial</a> (which is now deprecated like <a href="https://stackoverflow.com/questions/17881282/receive-a-message-on-a-device-with-gcm">many other questions and answers</a> about this) for the server-side functions, which look to work as expected since I can get this kind of outputs :</p>
  
  <pre><code>{"multicast_id":9131068334342174816,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1377441098827443%1d84a26ff9fd7ecd"}]}
  </code></pre>
  
  <p>But according to <a href="https://stackoverflow.com/questions/11409119/android-gcm-doesnt-work">some answers</a>, receiving this response just means that the message has been accepted by GCM servers for sending, but not that it has been sent. So, as expected, my <code>BroadcastReceiver</code> doesn't receive anything.</p>
  
  <p>Here's my <code>BroadcastReceiver</code> code :</p>
  
  <pre><code>public class GcmBroadcastReceiver extends BroadcastReceiver {
      @Override
      public void onReceive(Context context, Intent intent) {
          Log.i("gcm_debug", "PushReceiver onReceive called");
  
          Bundle extras = intent.getExtras();
          GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
  
          String msgType = gcm.getMessageType(intent);
  
          if(!extras.isEmpty()){
              if(GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(msgType)){
                  Log.i("gcm_debug", "Message send error");
              }else if(GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(msgType)){
                  Log.i("gcm_debug", "Message deleted");
              }else if(GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(msgType)){
                  Log.i("gcm_debug", "Message received : " + extras.toString());
              }
          }
  
          setResultCode(Activity.RESULT_OK);
      }
  
  }
  </code></pre>
  
  <p>And my <code>AndroidManifest</code> :</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
  &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /&gt;
  &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;
  
  &lt;permission android:name="&lt;MYAPP&gt;.permission.C2D_MESSAGE"
              android:protectionLevel="signature" /&gt;
  &lt;uses-permission android:name="&lt;MYAPP&gt;.permission.C2D_MESSAGE" /&gt;
  
  &lt;!-- Require OpenGL ES2 for GMap --&gt;
  &lt;uses-feature android:glEsVersion="0x00020000"
                android:required="true" /&gt;
  
  
  &lt;!-- Because this app is using the GCM library to send messages, the min SDK cannot be lower
  than 8 --&gt;
  &lt;uses-sdk
      android:minSdkVersion="8"
      android:targetSdkVersion="18" /&gt;
  
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/LovRTheme" &gt;
      &lt;receiver
          android:name=".GcmBroadcastReceiver"
          android:permission="com.google.android.gcm.c2dm.permission.SEND" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
              &lt;!-- &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt; --&gt;
              &lt;category android:name="&lt;MYAPP&gt;" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
      &lt;service android:name=".GcmIntentService" /&gt;
  </code></pre>
  
  <p>And the server-side code :</p>
  
  <pre><code>    $url = "https://android.googleapis.com/gcm/send";
      $fields = array(
          'registration_ids' =&gt; array($dstRegId),
          'delay_while_idle' =&gt; true,
          'data' =&gt; array("message" =&gt; $message));
  
      $headers = array(
          'Authorization: key=' . $google_api_key,
          'Content-Type: application/json');
  
      $ch = curl_init();
  
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  
      curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
  
      $result = curl_exec($ch);
      if($result === FALSE){
          die("Curl failed");
      }
      curl_close($ch);
  
      echo $result;
  </code></pre>
  
  <p>I'm coding from home, so I assume that GCM would not have problems getting in and out of the network since GCM uses a kind of reverse-shell connection. Anyway, i don't receive any of the log output i'm expecting.</p>
  
  <p><strong>EDIT:</strong>
  After leaving my app running for a while, LogCat sent me the following outputs :</p>
  
  <pre><code>08-26 00:00:48.984  17966-17966/? D/GCM: Ignoring attempt to send heartbeat on dead connection.
  08-26 00:01:49.000  17966-17966/? D/GCM: Ignoring attempt to send heartbeat on dead connection.
  08-26 00:02:01.672      433-448/? W/BroadcastQueue: Permission Denial: broadcasting Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=&lt;myApp&gt; (has extras) } from com.google.android.gsf (pid=17966, uid=10003) requires com.google.android.gcm.c2dm.permission.SEND due to receiver com.navissal.lovr/com.navissal.lovr.GcmBroadcastReceiver
  08-26 00:17:09.063  17966-17966/? D/GCM: Ignoring attempt to send heartbeat on dead connection.
  08-26 00:18:09.086  17966-17966/? D/GCM: Ignoring attempt to send heartbeat on dead connection.
  08-26 00:24:15.250    3936-3951/? V/meshclient: uri: [/beacon?e=wTkyFfdWFtlzOme7rNizVCtnUu9t3SbJgKCe72og-OhyhGIYab1QikytBeU2Nc02QwdDtqI4sX7HHU6GpDQL8zZdKXFXmCics6ZG-Jmr84yvMX1x9EqdyyW1UI6PEhoOb9MV4R_msQ_MEWFnwUzQrV-vGTycKtSNKMMIRE-zM1caIe__7hdu_UStbhz0dhl7cAFmHYF74IQI6EYFCEORxgV2Wts4Ls-hRWEKfEzuBhViND7TeCVpqUOhdVwGMnDO_Qwlo0rpuSNFegdfJCYY4L8fZJogPsXdQW2cFSZ2S0kujCH9uIrljFUTSGcM5GCFuJRq8vWiTP07MqpMq7h2fGGpXQvjImFcVP81erkVzvlYu3bNpjyQe6MhxSFEZrG37Kdp2Fd3liXFZzSjKlLILeYsDK9rRYqO8fEy3PH07et1HjqYWrH-v7wnjcQm6TtyZu914oR-dPBAwX9D3WvbdQlPlqxnuwJ1huUTwaiKotPLgrAzo3Mc5vI93VTs3row]
  </code></pre>