0

in my Android app I use GCM for sending and receiving upstream and downstream messages via XMPP-Protcol. When sending messages, the receiver receives these in most cases immediately. But sometimes the receiver gets the same message twice after some hours are gone.

I've already read many threads treating this issue, but can't find a solution helping me.

What I've already tried:

I use canonical tokens for registration and token refresh routines like following implementation shows:

// make sure to delete all associated tokens to this device

InstanceID.getInstance(getApplicationContext()).deleteInstanceID();

// get new token

InstanceID instanceID = InstanceID.getInstance(ctxt);
String token = instanceID.getToken(senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

//send token to backend

// store token in sharedPref

In think handling registration and token refresh this way there might be no multiple tokens belonging to one device, what means addressing one device by multiple tokens or sending messages via multiple tokens should be prevented. Unfortunately, messages are still received twice sometimes with different delays.

I use following version in my app gradle code for dependencies:

compile 'com.google.android.gms:play-services-gcm:8.4.0'

Does anyone face the same problems? How can I get rid of duplicate messages? Please let me know if you need further infos about my code to answer my question.

Johannes N
  • 265
  • 3
  • 17
  • I found this in GitHub - [Duplicate pushes received for a single device](https://github.com/buddycloud/buddycloud-pusher/issues/17), and based from the thread, Google already handled this issue through Canonical IDs. However, you mentioned that you also used canonical tokens for registration and token refresh routines. Have you also read about the procedure on canonical registration id from GCM in this SO post - [Canonical Registration ID and message ID format](http://stackoverflow.com/questions/12808959/canonical-registration-id-and-message-id-format/12978274#12978274)? – Teyam Jul 14 '16 at 10:48
  • 1
    Could you describe how you are storing the tokens on the server side. IID tokens may continue to work after deletion for some time so you should be removing the deleted IID tokens from your server otherwise that may result in sending multiple messages to the same device if you are sending to all tokens on the server. – Arthur Thompson Jul 14 '16 at 16:27
  • Whenever I send a token to the backend, either a user gets a new record if he has registered for the first time or if he has already assigned a token, this one will be updated. So every user must forcingly have the latest token that was assigned to his mobile device in the database. I think that's not the problem. – Johannes N Jul 14 '16 at 20:47
  • Finally, I came to the conclusion that I handle the duplicate messages by myself. I can't rely on upstream messaging using GCM facing this issue again and again. This problem obviously occurs only when sending upstream messages from the mobile device via the GCM connection cloud server to my application server. I can't controle or monitor what is going on Googles Connection Cloud Server. So what I did, is check each new incoming message by comparing its timestamp with the timestamp saved in my database and a corresponding user id. Dupilcate message can be caught that way. And see it works. – Johannes N Jul 14 '16 at 20:55
  • I drop duplicate messages by comparing the FCM (GCM) ID plus the message number to a list of previously processed messages. The documentation does say "If the connection between CCS and the device is poor, Firebase Cloud Messaging may send multiple, duplicate delivery receipts. You can safely ignore such duplicates." BUT I get duplicates with delivery_receipt_requested set to false. It doesn't feel right but seem necessary and doesn't cause apparent harm. NOTE: I do ack the duplicate message - I just don't process it further. – Ayyrk Mar 01 '17 at 18:59

0 Answers0