Updating the GCM token and when to send the token to the server

I follow the example of GCM-Android from the official guide.

In particular, I got confused in the following lines in the class linked above:

// You should store a boolean that indicates whether the generated token has been
// sent to your server. If the boolean is false, send the token to your server,
// otherwise your server should have already received the token.

Now I call the intent service every time my main view starts, and I believe that instanceID is responsible for initiating the token update.

Do I have to check the value of Shared Prefs every time I initiate this intention of registering GCM from my main activity. However, the update in this case will not be performed, because after the initial selection of the token, the condition will always be true.

Should I abandon the general logic of prefs - this way, a new token will be sent to my server every time. What is the right way to do this? How does the token update and when is it updated?

+4
source share
1 answer

Yes, you do not need to save it in sharedPreference. To protect the client application and the application server from possible malicious reuse of registration tokens, you should periodically initiate a token update from the server. When updating the GCM registration token is initiated on the server side, the client application should process the tokenRefreshed message confirming the acknowledgment of the GCM client / server.

, , Google Cloud Messaging, . , , , API GCM . , , . , .

Google - MyInstanceIDListenerService: https://github.com/googlesamples/google-services/blob/master/android/gcm/app/src/main/java/gcm/play/android/samples/com/gcmquickstart/MyInstanceIDListenerService.java#L38

, , Google : https://developers.google.com/cloud-messaging/registration

+5

Source: https://habr.com/ru/post/1628442/


All Articles