The AndroidManifest.xml:
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Receiver for GCM Messages-->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<action android:name="com.google.android.c2dm.intent.GCM_RECEIVED_ACTION"/>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="de.comp.module.client" />
</intent-filter>
</receiver>
<service
android:name="de.comp.module.client.gcm.GCMBroadcastIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
The GCMBroadcastIntentService class:
public class GCMBroadcastIntentService extends GcmListenerService {
@Override
public void onMessageReceived(String from, Bundle extras) {
if (extras.containsKey("message")) {}
}
}
The onMessageReceived() method is never called. The server works fine, the messages are send to Google GCM without any errors, but they never arrive at the device. I also use google-services.json which is stored in the folder /app. In my app the user can loggin after a new installation. In this case a new GCM token is requested and send to the server. So it should be correct and up to date.
What is missing? Thanks for your help.
EDIT:
public class GCMRegistrationIntentService extends IntentService {
@Override
protected void onHandleIntent(Intent intent) {
try {
// register server key to GCM
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
String regid = gcm.register(getString(R.string.gcm_defaultSenderId));
// Request new token for this server key
InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
// Subscribe to topic channels
subscribeTopics(token);
...
}