Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android C2DM : Duplicate message to the same device and App

I'm wondering if anyone has faced this issue with Google C2DM? This is the scenario I am faced with:

  1. User installs the app and registers with C2DM server for a registration key.
  2. User uninstalls the app.
  3. User reinstalls the app (and registers with C2DM server for new registration key).

Now I send message from my server to the user's phone and they get a duplicate message.

Could anyone shed any insight into wether this is expected behaviour or how I can fix it? Thanks,

like image 545
Anh Nguyen Avatar asked Feb 02 '23 16:02

Anh Nguyen


2 Answers

Not sure if this is the best approach, but there's a relevant thread over at the android-c2dm group, where the poster offers one technique:

I am sending registration id in the message, so I can check it against the stored registration id on the device.

If it's not the same, discard it and notify the service that registration Id is no longer in use

Downside is sending registration Id takes up some space in already limited message size. But works perfectly in my case since my original message is no more than a few chars long.

like image 121
Roman Nurik Avatar answered Feb 05 '23 06:02

Roman Nurik


This should only happen for the first push notification after re-installing your application.

Google C2DM service is working in passive mode when it comes to detecting uninstalled applications.

First push notification after uninstalling your application (without unregistering from C2DM!!!) will NOT return any error in response. However, the second push notification will return an "invalid registration" or "not registered" error codes where you can realize the application was uninstalled.

The reason is that C2DM servers return the response code immediately and only then tries to push the client. When client respond that an application was uninstalled, it is deleted from C2DM servers. Next push attempt will return an error code immediately.

like image 39
Zamel Avatar answered Feb 05 '23 06:02

Zamel