I would like to send the GCM deviceToken to my server so that I can trigger push notifications using the REST API. All this works, except that I cannot reliably get the deviceToken when it becomes available. When I register an application to receive push notifications on a broadcast channel, I check deviceToken for a done() callback. However, it is often not yet installed. I'm looking for a way to get deviceToken the moment it becomes available, so I can avoid polling or wait for the application to restart to send push notifications.
What i tried
Capture device Register in the channel registration callback
Parse.initialize(this, applicationId, clientKey) { ParsePush.subscribeInBackground("", new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { String deviceToken = (String) ParseInstallation.getCurrentInstallation().get("deviceToken");
Device Capture Tap in ParseInstallation.saveInBackground ()
final ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation(); parseInstallation.saveInBackground(new SaveCallback() { @Override public void done(ParseException e) { String deviceToken = (String) parseInstallation.get("deviceToken");
Listening to the GCM registration event yourself by subclassing com.parse.GcmBroadcastReceiver
source share