GCM: onMessage() from GCMIntentService is never called
<p>I am implementing <code>GCM (Google Cloud Messaging- PUSH Notifications)</code> in my application. I have followed all the steps given in GCM tutorial from developer.android.com</p>

<p>My application's build target is pointing to <code>Goolge API 8 (Android 2.2 version)</code>.</p>

<p>I am able to get the register ID from GCM successfully, and I am passing this ID to my application server. So the registration step is performed successfully.</p>

<p>Now when my application server sends a PUSH message to my device, the server gets the message as <code>SUCCESS=1 FAILURE=0, etc.</code>, i.e. Server is sending message successfully, but my device never receives the message.</p>

<p>After searching alot about this, I came to know that GCM pushes messages on port number 5228, 5229 or 5230.</p>

<p>Initially, my device and laptop was restricted for some websites, but then I was granted all the permissions to access all websites, so I guess these port numbers are open for my device.</p>

<p>So my question is: <strong>I never receive any PUSH message from GCM. My onMessage() from GCMIntenService class is never called. What could be the reason?</strong></p>

<p>Please see my following code and guide me accordingly:</p>

<p>I have declared following in my manifest:</p>

<pre><code>&lt;uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" /&gt;

    &lt;permission
        android:name="package.permission.C2D_MESSAGE"
        android:protectionLevel="signature" /&gt;

    &lt;!-- App receives GCM messages. --&gt;
    &lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;

    &lt;!-- GCM connects to Google Services. --&gt;
    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;

    &lt;!-- GCM requires a Google account. --&gt;
    &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;

    &lt;!-- Keeps the processor from sleeping when a message is received. --&gt;
    &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
    &lt;uses-permission android:name="package.permission.C2D_MESSAGE" /&gt;
    &lt;uses-permission android:name="android.permission.INTERNET" /&gt;

    &lt;receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
                &lt;action android:name="com.google.android.c2dm.intent.REGISTRATION" /&gt;

                &lt;category android:name="packageName" /&gt;
            &lt;/intent-filter&gt;
        &lt;/receiver&gt;
        &lt;receiver
            android:name=".ReceiveBroadcast"
            android:exported="false" &gt;
            &lt;intent-filter&gt;
                &lt;action android:name="GCM_RECEIVED_ACTION" /&gt;
            &lt;/intent-filter&gt;
        &lt;/receiver&gt;

        &lt;service
            android:name=".GCMIntentService"
            /&gt;


/**
 * @author Shrikant.
 * 
 */
public class GCMIntentService extends GCMBaseIntentService {

    /**
     * The Sender ID used for GCM.
     */
    public static final String SENDER_ID = "myProjectID";

    /**
     * This field is used to call Web-Service for GCM.
     */
    SendUserCredentialsGCM sendUserCredentialsGCM = null;

    public GCMIntentService() {
        super(SENDER_ID);
        sendUserCredentialsGCM = new SendUserCredentialsGCM();
    }

    @Override
    protected void onRegistered(Context arg0, String registrationId) {
        Log.i(TAG, "Device registered: regId = " + registrationId);
        sendUserCredentialsGCM.sendRegistrationID(registrationId);
    }

    @Override
    protected void onUnregistered(Context context, String arg1) {
        Log.i(TAG, "unregistered = " + arg1);
        sendUserCredentialsGCM
                .unregisterFromGCM(LoginActivity.API_OR_BROWSER_KEY);
    }

    @Override
    protected void onMessage(Context context, Intent intent) {
        Log.e("GCM MESSAGE", "Message Recieved!!!");
        String message = intent.getStringExtra("message");
        if (message == null) {
            Log.e("NULL MESSAGE", "Message Not Recieved!!!");
        } else {
            Log.i(TAG, "new message= " + message);
            sendGCMIntent(context, message);
        }
    }

    private void sendGCMIntent(Context context, String message) {
        Intent broadcastIntent = new Intent();
        broadcastIntent.setAction("GCM_RECEIVED_ACTION");
        broadcastIntent.putExtra("gcm", message);
        context.sendBroadcast(broadcastIntent);
    }

    @Override
    protected void onError(Context context, String errorId) {
        Log.e(TAG, "Received error: " + errorId);
        Toast.makeText(context, "PUSH Notification failed.", Toast.LENGTH_LONG)
                .show();
    }

    @Override
    protected boolean onRecoverableError(Context context, String errorId) {
        return super.onRecoverableError(context, errorId);
    }
}
</code></pre>
