Android Gcm Unregister Users Subscribed To A Topic When App Uninstalled

1.7k views Asked by At

Scenario: I have a 3rd-party app server, a gcm http connection server, and an android app setup for push notifications. When the user uninstalls the app, I can delete them from my 3rd-party server by sending their (no-longer-valid) registration id a push notification and handling the "NotRegistered" error returned from the gcm connection server.

However, this similar approach does not seem to work when you send a push notification to users subscribed to a "Topic", as here the gcm connection server only returns a json object with the "message_id".

The notable columns in my 3rd-party server database table are as follows:

| gcmRegistrationID (string) | subscribedToNotificationTopic (boolean) |

Does anyone know how to identify a user that has previously set true in the subscribedToNotificationTopic column, then uninstalled the app?

I have an idea on how to resolve this, but it seems somewhat messy.

  1. Every so often, instead of only sending push notifications to a topic e.g.

    {
        "to" : "/topics/global",
        ...
    }
    

    send a push notification to the registration ids of the users subscribed to the topic e.g.

    {
        "registration_ids" : {list of registration ids},
        ...
    }
    

    such that I can retrieve and handle any "NotRegistered" errors.

The problem with this however, is that multicast messaging has a limit of 1000 users so I'd have to send a message for each thousand.

This seems like bad practice (especially if there is more than one topic involved), but maybe it's the only way?

(Extra tags: topic messaging, pubsub, unregister, google cloud messaging)

1

There are 1 answers

1
nPn On

First off, I am not sure it is correct to assume that an "NotRegistered" error can only be the result of the user uninstalling your app. It seems like the device can become unregistered if the device receives a message but that message can not be delivered. This can happen if the user stops the app (which is different from uninstalling it, or even if the app was killed and remains stopped due to a power saving mode.

https://developers.google.com/cloud-messaging/ccs#response

If it is NotRegistered, you should remove the registration ID from your server database because the application was uninstalled from the device, or the client app isn't configured to receive messages.

What you can do is from the device side, periodically register the device, and make sure that the token you get back is the same as the one you stored, if not update your server with the new token.

As far as detecting if a user has uninstalled your app via a response to a topic message, I agree with you it does not seem to be directly possible. As an alternative to your proposed solution, you might, every now and then include a flag in the topic message that would ask the device to validate itself with your server, if a device does not validate itself after some number of attempts or some period of time you might conclude the user is not longer listening.

The other question is why do you really need to know. Is there any harm in sending some extra regid's to google? If a user quits your web service you can remove them from the list, but do you really need to take action if they just un-install your app from there device? - Just some thing to consider. Hope this helps.