Check GCM Token

I am a bit confused about checking the GCM token. I work in a cross-platform application using the Sencha platform, and my server side is in Java. I have a question about how to check the registration identifier (GCM token)? Is there any specific API for checking a GCM token? Can you advise me how to handle this, both on the client side and on the server side? I already made the registration part on the server side, where the user can register the GCM token in the database. Now I need to check this registration token.

Does registering an application every 2 weeks a good approach?

+4
source share
2 answers

Solution for solving GCM verification using canonicalID link

private void asyncSend(List<String> partialDevices) { // make a copy final List<String> devices = new ArrayList<String>(partialDevices); threadPool.execute(new Runnable() { public void run() { Message message = new Message.Builder().build(); MulticastResult multicastResult; try { multicastResult = sender.send(message, devices, 5); } catch (IOException e) { logger.log(Level.SEVERE, "Error posting messages", e); return; } List<Result> results = multicastResult.getResults(); // analyze the results for (int i = 0; i < devices.size(); i++) { String regId = devices.get(i); Result result = results.get(i); String messageId = result.getMessageId(); if (messageId != null) { logger.fine("Succesfully sent message to device: " + regId + "; messageId = " + messageId); String canonicalRegId = result.getCanonicalRegistrationId(); if (canonicalRegId != null) { // same device has more than on registration id: update it logger.info("canonicalRegId " + canonicalRegId); Datastore.updateRegistration(regId, canonicalRegId); } } else { String error = result.getErrorCodeName(); if (error.equals(Constants.ERROR_NOT_REGISTERED)) { // application has been removed from device - unregister it logger.info("Unregistered device: " + regId); Datastore.unregister(regId); } else { logger.severe("Error sending message to " + regId + ": " + error); } } } }}); } 
+1
source

You register with GCM and do not register GCM on the client side. This means that you are getting a registration ID from Google.

After you have a registration identifier, you must consider it valid until:

  • You send a message with the registration ID to Google GCM Server and you receive a NotRegistered or InvalidRegistration error. In these cases, you must remove the registration identifier from your database.

  • You send a message with a registration ID to Google GCM Server and you receive a successful response, but the response contains a canonical registration ID. In this case, you must replace the registration identifier with the canonical registration identifier.

  • The application is clearly not registered with GCM and reported this to the server, in which case you must remove the registration identifier from your database.

I see no reason to abandon the application every two weeks. Sample Google code will only re-register the application as soon as a new version of it is installed, and even then they will not be uninstalled before re-registering.

+7
source