Search code examples
androidbroadcastreceivergoogle-cloud-messaging

GCMBroadcastReceiver not called


My GCMBroadcastReceiver is never called. I sent a message from my server via php to GCM, I got this from GCM, so my server side should be working:

{"multicast_id":XXX,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"XXXX"}]}

So the problem has to be in my AndroidManifest, but I can't find the solution, can you guys help me?

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<permission
    android:name="com.example.administrator.test.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.administrator.test.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive data message. -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

    <activity
        android:name=".RealMainActivity"
        android:label="@string/title_activity_real_main"
        android:noHistory="true" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <receiver
        android:name="com.example.administrator.test.GcmBroadcastReceiver"
        android:permission="com.google.android.cd2m.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <!-- Receives the registration id. -->
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.example.administrator.test" />
        </intent-filter>
    </receiver>

    <service
        android:name="com.example.administrator.test.GcmIntentService">
    </service>
</application>

GCMBroadCastReceiver.java

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Explicitly specify that GcmIntentService will handle the intent. ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName()); Log.i("GCMBroadcastreceiver", "werkt"); // Start the service, keeping the device awake while it is launching. startWakefulService(context, (intent.setComponent(comp))); setResultCode(Activity.RESULT_OK); } }


Solution

  • Try changing android:permission="com.google.android.cd2m.permission.SEND" to:android:permission="com.google.android.c2dm.permission.SEND"