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.