简体   繁体   English

重新安装Android App后,应用程序会收到旧安装的通知

[英]After reinstalling Android App the App gets notifications meant for the old installation

I know this has been discussed before, but the only solution I found (canonical IDs) don't work in my scenario. 我知道之前已经讨论过,但我发现的唯一解决方案(规范ID)在我的场景中不起作用。

Scenario: 场景:

  • User installs App and registers with his user account A 用户安装应用程序并使用其用户帐户A注册
  • User gets push notifications meant to be delivered to this specific user account A 用户获得旨在传递给此特定用户帐户A的推送通知
  • User uninstalls the app 用户卸载该应用程序
  • User reinstalls the app 用户重新安装该应用程序
  • User registers with a different user account B 用户使用其他用户帐户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. 根据我的理解,使用cannonical GCM Reg ID只会合并这些ID并阻止发送重复通知。 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. 我唯一能想到的就是在卸载应用程序时主动取消注册,但在我读过的另一个线程中,卸载时无法执行代码。

From my understanding, using cannonical GCM Reg IDs would only consolidate those IDs and prevent sending duplicate notifications. 根据我的理解,使用cannonical GCM Reg ID只会合并这些ID并阻止发送重复通知。

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 ". 这是查看它的一种方式,但更简单的说明,Canonical ID就像是说“ 您使用的旧ID已过期,删除它(如果您保存它)并使用我 ”。

The thing that makes this a bit odd is that, when the user uninstalls the app, the InstanceID should be invalidated. 使这有点奇​​怪的是,当用户卸载应用程序时,InstanceID应该无效。 (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. 我认为您可以做的是确保删除令牌,您可以调用deleteInstanceId()来撤销所有令牌,然后重新注册。

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): 但是为了确保该消息是针对目标用户的,您可以参考文档中所述的内容(第一个类似于@ Ak9637所说的内容):

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. 然后,客户端应用程序可以检查以确保它接收的消息与登录用户匹配。

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. 您只需检查在您的令牌数据库中注册时,当您收到用户B的令牌时,只需检查它是否已与任何用户关联,如果它只是取消该字段并将新令牌保存给新用户。 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 如果您希望完全自主并控制与您的应用相关的通知,您应该使用数据通知而不是消息通知,这将避免操作系统处理通知而不是您的应用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM