当前位置: 动力学知识库 > 问答 > 编程问答 >

android - GCM multiple device tokens

问题描述:

When a different user logs in from the same device after reinstalling the app, multiple device tokens get inserted for the same user on the application server. This is because at the application server we are disabling all userIds mapped to the same GCM registrationId. This was done to handle logging in of a different user from the same device by clearing data(In this case device token remains same, so comparing solved the problem). And as we are sending the notification in bulk we can't get map the canonical Id's to the users and disable them.

My code at the server is:

 MulticastResult result = null;

Sender sender = new Sender(GOOGLE_SERVER_KEY);

Message messag = new Message.Builder().timeToLive(86400)

.delayWhileIdle(false)

.addData(MESSAGE_KEY, notificationJsonObject.toString())

.build();

try {

Result result = sender

.sendNoRetry(messag, androidDevicesTokens);

result.getResults().get(0).getCanonicalRegistrationId();

} catch (IOException e) {

e.printStackTrace();

}

网友答案:

And as we are sending the notification in bulk we can't get map the canonical Id's to the users and disable them

You should have no problem to map the Canonical ID to the old Registration ID that should be removed.

If result.getResults().get(i) contains a canonical Registration ID, the matching old Registration ID to be removed is androidDevicesTokens.get(i).

分享给朋友:
您可能感兴趣的文章:
随机阅读: