8

I'm stuck for a while on a mysterious problem. So I implemented GCM in my android app, but i receive an INVALID_SENDER error.

  • My SENDER_ID is the id from the url of the google project.
  • The Android push notifications are ON

The weird thing about this is that i already have a registration id to send notifications to. So my console looks like this:

03-26 09:39:20.233: I/<test>(19761): Already registered: APA91bG6-   O3OnZt50EAjYvJ5KETv3qAlPOn2SfOPXez7SLAmaAOkHTN6EMDJb91gFIWkftZkJiub6UoEk4O-  WQP7kk2oZGQjZ1VCZZS0WddQtjFaCfYfZfb7SEw3IS1sd4caJcdZE4LA1F0hxzc7Ss1UiYHXX-XXXX
03-26 09:48:23.522: I/<test>(19925): GCMIntentService 
03-26 09:39:20.670: I/<test>(19761): on Error INVALID_SENDER

Inside the onCreate:

GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
    Log.i("<test>", "registering");
        GCMRegistrar.register(this, "2194354949XX");
} else {
    Log.i("<test>", "Already registered: " + regId);
}

broadcastreceiver:

 public class GCMBroadcastReceiver extends com.google.android.gcm.GCMBroadcastReceiver{
    @Override
    protected String getGCMIntentServiceClassName(Context context){
        return "be.XXX.XXX.system.GCMIntentService";
    }
}

GCMIntentService:

 public class GCMIntentService extends GCMBaseIntentService {
    @Override
    protected void onError(Context arg0, String errorId) {
        Log.i("<test>","on Error " + errorId);
    }

    @Override
    protected void onMessage(Context arg0, Intent intent) {
        Log.i("<test>","onMessage " + intent.getExtras().toString());
    }

    @Override
    protected void onRegistered(Context arg0, String regId) {
        Log.i("<test>","Registration id: " + regId);
    }

    @Override
    protected void onUnregistered(Context arg0, String regId) {
        Log.i("<test>","onUnregistered " + regId);
    }

    public GCMIntentService() {
        super("2194354949XX");
        Log.i("<test>","GCMIntentService ");
    }
}

Manifest:

 <permission
    android:name="com.XX.XX.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.smstiming.hezemans.permission.C2D_MESSAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />



<receiver android:name="be.XX.XX.system.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="com.smstiming.hezemans" />
        </intent-filter>
    </receiver>

 <service android:name="be.XX.XX.system.GCMIntentService" /> 
Manuel Allenspach
  • 12,467
  • 14
  • 54
  • 76
Zillan
  • 720
  • 7
  • 15
  • 1
    look for log `03-26 11:23:38.704: V/GCMRegistrar(1389): Registering app your.packagename.com of senders XXXXXX` were `XXXXXX` is the actual sender that send to google! – madlymad Mar 26 '13 at 09:28
  • You helped me in the right direction. It is fixed now. Forgot to turn off the old C2DM version -_-.. – Zillan Mar 26 '13 at 10:23

3 Answers3

10

Finally got around this. Was accidentally trying to use the the 'Project ID' instead of the 'Project Number'. Google Developer Console provides both on the Overview page, make sure you are using the correct one.

Marchy
  • 3,334
  • 5
  • 37
  • 27
0

Forgot to turn off the C2DM service. Silly me..

Zillan
  • 720
  • 7
  • 15
  • 4
    can you clarify what you mean by forgot to turn off the C2DM service? what did you have to do to turn it off? – Adam Johns Aug 22 '13 at 14:53
  • check google's api console and ensure gcm is enabled but c2dm isn't? (that's a guess, not OP but having the same problem) – edthethird Feb 13 '14 at 17:30
0

Maybe your senderID is not true. You should create constructor for GCMIntentService class and call super(<SenderId>).

nurisezgin
  • 1,530
  • 12
  • 19