我在手机中为我的应用程序实现 gcm 时犯了一个错误,现在它没有收到任何通知。同一个应用程序在任何其他设备上都能完美运行(接收 gcm 通知)。我需要从 gcm 中取消注册我的手机,我应该怎么做?
我应该等待 7 天(默认到期时间)吗?
最佳答案
您可以针对单个设备尝试以下注销过程(卸载应用程序并稍后重新安装)。 (注意,这是来自 Google Cloud Messaging 高级文档 here )
How unregistration works
An application can be automatically unregistered after it is uninstalled from the device. However, this process does not happens right away, as Android does not provide an uninstall callback. What happens in this scenario is as follows:
- 最终用户卸载应用程序。
- 第 3 方服务器向 GCM 服务器发送消息。
- GCM 服务器将消息发送到设备。
- GCM 客户端收到消息并查询包管理器是否配置了广播接收器来接收它,结果返回 false。
- GCM 客户端通知 GCM 服务器 > 应用程序已卸载。
- GCM 服务器标记要删除的注册 ID。
- 第 3 方服务器向 GCM 发送消息。
- GCM 向第 3 方服务器返回 NotRegistered 错误消息。
- 第 3 方删除注册 ID。
Note: The GCM client is the Google Cloud Messaging framework present on the device.
Note that it might take a while for the registration ID be completely removed from GCM. Thus it is possible that messages sent during step 7 above gets a valid message ID as response, even though the message will not be delivered to the device. Eventually, the registration ID will be removed and the server will get a NotRegistered error, without any further action being required from the 3rd-party server (this scenario happens frequently while an application is being developed and tested).
关于java - 如何重置设备的 Google Cloud Messaging 注册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25240974/