Dave Thomas Dave Thomas - 1 year ago 121
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.


<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" />

android:permission="com.google.android.gcm.c2dm.permission.SEND" >
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="<pkgname>" />

<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}}}


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.


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 {

public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(),
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));

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 Source

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"/>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download