droidev
droidev

Reputation: 7380

Get Different GCM registrationId for Different servers

I am using GCM for triggering notification to my android app. notification are triggered from my server. for example suppose the user registers an account in app then server will be sending notifications for that I am passing GCM registration id in my registration request. till now it works perfectly. now I have one more API that is another server. and I am sending the same GCM Registration Id in that request, but I am not getting any notification from that server, so from some reading I have found that each registration_id is associated with a particular app and its corresponding server API key i.e. a single device has different registration_ids for different apps Thus, we got a MismatchSenderId error while trying to send push notifications using the registration_id. how do I resolve this ? I have googled and didn't find any proper solution.

I am generating GCM registration in this way :

 String token = instanceID.getToken(defaultSenderId),
                        GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

Upvotes: 2

Views: 129

Answers (2)

cVoronin
cVoronin

Reputation: 1350

There can be an issue in case when a token is updated: in InstanceIDListenerService I see no way to identify token was updated - for sender_1 or for sender_2. So it seems when onTokenRefresh is called we have to get new tokens for both senders.

Upvotes: 1

goblin
goblin

Reputation: 1553

Since you have 2 different servers, I believe you have two different sender ID. So in your code, you must have 2 token, one for each server.

Sample:

Token for server 1:

String token = instanceID.getToken(<sender_id_1>),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

Token for server 2:

String token2 = instanceID.getToken(<sender_id_2>),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

Upvotes: 3

Related Questions