Dave Thomas Dave Thomas - 3 months ago 30
Android Question

GCM message sending successfully on server but not received on Device

Maybe a second set of eyes can help me here. Can't seem to get anything in my Receiver, even though I'm getting successful sends when posting to gcm send url from my server.

Manifest:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />



<permission android:name="<pkgname>.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="<pkgname>.permission.C2D_MESSAGE" />

<receiver
android:name="<pkgname>.GcmBroadcastReceiver"
android:exported="true"
android:permission="com.google.android.gcm.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="<pkgname>" />
</intent-filter>
</receiver>

<service android:name="<pkgname>.GcmIntentService" />


= com.myappsname I've removed it for privacy sake

Here is the server request and response:

{"registration_ids":[removed],"data":{"project":{"comment":"Chubb","username":"Dave Thomas","time":"2014-12-05 15:33:13","projectId":5}}}

{"multicast_id":removed,"success":2,"failure":0,"canonical_ids":1,"results":[{"message_id":"removed"},{"registration_id":"removed","message_id":"removed"}]}


So server is sending successfully... but not seeing anything on the app side at all. Put a break point at the start of the receiver's onReceive method, and it isn't catching anything.

receiver:

package <pkgname>;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.support.v4.content.WakefulBroadcastReceiver;

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());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}


Update found this in my log, so I know device is actually geting message:

12-08 12:48:42.910: W/BroadcastQueue(960): Permission Denial: broadcasting Intent { act=com.google.android.c2dm.intent.RECEIVE flg=0x10 pkg=<pkgname> (has extras) } from com.google.android.gsf (pid=28999, uid=10007) requires com.google.android.gcm.c2dm.permission.SEND due to receiver <pkgname>/.GcmBroadcastReceiver


I think I've found my issue

Answer

The problem is in my receiver decleration in my AndroidManifest:

<uses-permission android:name="com.google.android.gcm.c2dm.permission.SEND"/>

Should be:

<uses-permission android:name="com.google.android.c2dm.permission.SEND"/>