清除应用程序数据不清除 GCM 令牌或 GCM 订阅主题

Clearing app data not clearing GCM token nor GCM subscribing topics

我已经从 GCM 订阅了主题,当我通过 android 设置删除所有应用程序数据时,GCM 令牌是相同的,关于主题的 GCM 通知仍然可用,所以我收到了我不知道的通知我不想收到。

我的问题是:

How can I get list all of subscribing topics from gcm?

当前版本的 GCM 未提供执行此操作的方法。

How can I remove all of subcribing topics without knowing their names?

documentation indicates InstanceId.deleteInstanceID() 会这样做。

Should GCM token be changed after clear app data or removed all subscribing topics in this case automatically?

虽然 documentation implies that token registrations and subscriptions are removed if the user clears app data, that is not true in the current version of GCM. The issue is discussed in the answer to this related .

  1. 我建议你不能只使用调试工具:) 例如,您必须在 sharedprefs 中保存订阅的主题。如果您在 sharedpreferences 中没有令牌,您应该调用 instanceId.deleteInstanceID()

  2. 直接调用instanceId.deleteInstanceID()

  3. 令牌很少更改,但当它更改时,您必须重新订阅所有主题。

也结帐this question on SO


工具

可以使用this工具调试:)

当我不订阅任何主题时,我会得到这样的信息:

{
    "applicationVersion": "39",
    "connectDate": "2016-01-12",
    "application": "com.esportlivescore.develop.debug",
    "authorizedEntity": "114434000000000",
    "connectionType": "MOBILE",
    "appSigner": ".................",
    "platform": "ANDROID"
}

订阅某个主题后:

{
    "applicationVersion": "39",
    "connectDate": "2016-01-12",
    "application": "com.esportlivescore.develop.debug",
    "authorizedEntity": "11443413691531",
    "rel": {
        "topics": {
            "match-28388-start": {
                "addDate": "2016-01-13"
            }
        }
    },
    "connectionType": "MOBILE",
    "appSigner": ".................",
    "platform": "ANDROID"
}

如此简单的用法。我使用高级 REST 客户端 (plugin for Chrome)

HTTP GET 请求

https://iid.googleapis.com/iid/info/<TOKEN>?details=true
Content-Type:application/json
Authorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA

令牌 在 url 中:token obtainet from google

key : 可以在 Google Developer Console / GCM Console

中找到