Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Cloud Messaging (GCM) and missmatched sender id

I am trying to use the GCM service in my android app.

For that, I used the android documentation from http://developer.android.com/guide/google/gcm/gcm.html

I created the client side registration process with the sender id etc and the server side application where I am using the registration id and the sender id to send messages.

When I am installing the app in my phone through Eclipse, the push notifications works fine, so the sender id i have is right.

Then, when i export the apk file with Eclipse and install it in my phone, I am getting the error message that the SenderId is wrong

MissmatchedSenderId

Anyone has an idea whyI am getting this.

I have read those topics:

Why do I get "MismatchSenderId" from GCM server side?

When sending messages using GCM, I keep getting the response 'MismatchSenderId'

But the strange thing in my case is that everything works fine before exporting the app as apk and then I have this problem.

Any idea is mostly wellcome.

like image 790
Milos Cuculovic Avatar asked Oct 18 '12 07:10

Milos Cuculovic


2 Answers

I actually had the same problem, and was researching more than 10 hours.

I finally found out the problem! Nothing related to the Server API key or Browser API Key or SenderID. The problem was the Google documentation:

final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
  GCMRegistrar.register(this, SENDER_ID);
} else {
  Log.v(TAG, "Already registered");
}

Google says that you have to call the getRegistrationId function and only if the id is empty call register! Which did not work for me at all... when I did that I always got back MismatchSenderId when sending to this regId.

My solution was: Always call

GCMRegistrar.register(this, SENDER_ID);

and when the function

protected void onRegistered( Context c, String regId )

is called save the regId in my server database.

if I do it this way, all works fine!

like image 74
schurtertom Avatar answered Oct 14 '22 16:10

schurtertom


The combination of SenderID and API key provided by GCM is unique per application.

We faced the senderID mismatch issue, when we updated our senderID on the client side but still used the API key related to old senderID.

We were able to resolve the issue after we updated the server API key. Also the answer by @schurtertom is very helpful

like image 34
Vikas Avatar answered Oct 14 '22 18:10

Vikas