2

I know this has been discussed before, but the only solution I found (canonical IDs) don't work in my scenario.

Scenario:

  • User installs App and registers with his user account A
  • User gets push notifications meant to be delivered to this specific user account A
  • User uninstalls the app
  • User reinstalls the app
  • User registers with a different user account B

Now notifications are delivered for both user accounts. From my understanding, using cannonical GCM Reg IDs would only consolidate those IDs and prevent sending duplicate notifications. In this case the App gets notifications for a different user that shouldn't be delivered at all.

Is there any fix for that? Only thing I can think of would be actively deregistering when uninstalling the app, but in another thread I read, it's not possible to execute code on deinstallation.

Chry007
  • 521
  • 2
  • 7
  • 25

2 Answers2

3

From my understanding, using cannonical GCM Reg IDs would only consolidate those IDs and prevent sending duplicate notifications.

That's one way of looking at it, but on a simpler note, Canonical IDs are like saying "old ID you used is expired, delete it (if you saved it) and use me instead".

The thing that makes this a bit odd is that, when the user uninstalls the app, the InstanceID should be invalidated. (see the docs here).

What I think you can do to make sure that tokens are deleted, you can call deleteInstanceId() to revoke all tokens, then re-register.

But to make sure that the message is for the intended user, you can refer to what is stated in the docs (first one similar to what @Ak9637 said):

To make sure that messages go to the intended user:

  • The app server can maintain a mapping between the current user and the registration token.

  • The client app can then check to ensure that messages it receives match the logged in user.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • Hm. So calling deleteInstanceId() on the very first appstart after reinstallation it should invalidate the old installation's token and then from there I could reregister and only use the new token? Did I get that right? – Chry007 Nov 25 '16 at 07:41
  • @Chry007 Yup. But that is presuming that the InstanceId wasn't invalidated. Normally, the App uninstall should invalidate the InstanceId automatically, making the associated tokens expire. Odd behavior on your case tho. Maybe something's amiss. Do some further testings and let me know if it works. – AL. Nov 25 '16 at 11:16
  • @Chry007 just wanted to check in, were you able to try it out? – AL. Dec 07 '16 at 10:15
  • nope. Unfortunately we prioritized this down. It's on the list though and I'll update here as soon as we get back to it. – Chry007 Dec 13 '16 at 14:37
1

You can simply check ,when registering in your tokens database,when u receive token of user B , just check if it is already associated with any user or not, if it is simply nullify that field and save the new token to new user. As token identifies the device not the user.

If you wish to take total autonomy and control of notifications related to your app, You should use data notifications instead of message notifications , this will avoid the OS handling the notifications instead of your app

Ak9637
  • 990
  • 6
  • 12
  • Would work if the App wasn't multi user. So it is possible, that different users have the same token. I need to specifically know which token belongs to which registration(s). – Chry007 Nov 24 '16 at 10:14
  • 1
    in that case you can simply,make the notifications to be handled only by your app not the OS,this can be achieved by getting a data notification instead of normal notification, once you recieve this data notification ,client side can implement whatever logic of checking that you want – Ak9637 Nov 24 '16 at 10:17
  • And to add to this,I m assuming that a single user would be signed on one device.and in one device at a time only one user is logged in . please details your requirement ,y u need to have multiple users associated to same device when login user at any give time will be just 1 – Ak9637 Nov 24 '16 at 10:19
  • I think checking on client side seems to be the only viable option. It's multiple users who can register to multiple providers to receive information specific to the user - provider relationship. Each registration can receive push notifications and there can be several registrations on the same device as well as the same registration on multiple devices. I assume sending data notifications would hide this behavior from the user, but it would still be possible to retrieve the information from the notification on a device where the registration doesn't exist anymore, right? – Chry007 Nov 24 '16 at 10:52
  • Does the app get the same GCM Reg ID after reinstallation? Why is it even possible to deliver those notifications to an app installation that doesn't exist anymore? – Chry007 Nov 24 '16 at 10:52
  • Because even when u uninstall , the token corresponding are still valid – Ak9637 Nov 24 '16 at 10:55
  • But the notification is not shown, when the app is not installed. Just after the reinstallation, the apps shows notifications for the old installation. So the new installation gets the same registration id as the old one? – Chry007 Nov 24 '16 at 11:08
  • 1
    nope , the new app has the same package name as the old one, so if u r using message notification instead of data notification, android os will store the notification and display it on matching package name – Ak9637 Nov 24 '16 at 11:30
  • If you post the suggestion with data notification as an answer I'll mark it as the solution. Thanks for the help! – Chry007 Nov 24 '16 at 12:26
  • @Chry007 .... sure and ty ..... i will edit this answer itself.... u can mark this itself as solution so that other can benefit from the discussion in the comments too – Ak9637 Nov 24 '16 at 13:21
  • @Chry007 did it help u ? – Ak9637 Nov 25 '16 at 06:29