2

I just started working on google cloud messaging. I downloaded a sample from github. In the RegistrationIntnentService to get token from GCM Server we do

InstanceID instanceID = InstanceID.getInstance(this);
String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

and I don't understand what scope INSTANCE_ID_SCOPE defines on GCM Server.

Here it says

"Specifies scope used in obtaining GCM registrationToken when calling getToken(String, String)

Constant Value: "GCM""

And here the correct answer marked says

Note that you must use GoogleCloudMessaging.INSTANCE_ID_SCOPE as the second parameter - InstanceID is more general than just GCM, hence why it is a parameter that can take any String, but GCM specifically requires that authorization scope.

From what I understand from this is that you cannot replace INSTANCE_ID_SCOPE argument with a value other then "GCM" but I changed it and it is still receiving messages from GCM connection server.

Any help or documentation or link will be greatly appreciated.

Community
  • 1
  • 1
Abbas
  • 3,529
  • 5
  • 36
  • 64
  • Are you sending the message to the token generated with the non GCM scope? – Arthur Thompson Nov 04 '15 at 16:28
  • I did try that and it worked (strangely) although as I mentioned earlier if I understood the statement correctly then client should not have received message at all. – Abbas Nov 05 '15 at 05:15
  • What did you use as your non GCM scope? – Arthur Thompson Nov 05 '15 at 14:15
  • I don't remember now... whatever it was I used it to check if my understanding was correct, and then I changed it back to INSTANCE_ID_SCOPE. Further more doing some more research I found out that the value describes the scope of operation for the client on the GCM server. And its even more confusing because then it never should've worked. – Abbas Nov 06 '15 at 09:05
  • So either I luckily set the scope as some operation already defined or whatever. Or ....... (I am confused!) – Abbas Nov 06 '15 at 09:08
  • I understand your confusion but it is really difficult to reproduce the issue if you cannot remember the non GCM scope you used. When I provide a non GCM scope and send messages to the generated token the messages are not received, which is the expected behaviour. – Arthur Thompson Nov 08 '15 at 14:13

0 Answers0