关闭GCM通知

时间:2016-02-21 06:22:11

标签: android google-cloud-messaging gcmlistenerservice

我正在开发我正在使用GCM的应用程序。我从github的google示例中获取了示例GCM示例,并实现了一切都很好,但我想TURNOFF GCM通知。我已使用切换按钮在另一个活动中指定了GCM通知打开/关闭。当我点击切换按钮时,它应该相应地工作

我在RegistrationIntentService.java

中找到了subscribeTopics方法
private void subscribeTopics(String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for (String topic : TOPICS) {
        pubSub.subscribe(token, "/topics/" + topic, null);
    }
}

similarly i have written Un Subscribe method 

关闭通知

private void UnSubscribeTopics(String token) throws IOException {
    GcmPubSub pubSub = GcmPubSub.getInstance(this);
    for (String topic : TOPICS) {
        pubSub.unSubscribe(token, "/topics/" + topic, null);
    }
}

我无法调用UnSubscribeTopics方法。因为该方法在RegistrationIntentService.java中,它扩展了Intentservice.How我可以调用方法'UnSubscribeTopics'

I'm still getting notifications and here they are using Intent service.I have gone through internet some are saying to delete token(secret token) or delete instance id,but I'm confused what to do?? and how i do that .I am new to Intent service.here they using broadcast receiver also how can i call that in my activity.

任何帮助???

提前致谢。

1 个答案:

答案 0 :(得分:1)

您有两种选择:

  • 'SharedPreferences'如果应该通知用户,您应该具有包含值的首选项。您可以将首选项值设置为“false”。在“ GCMIntentService ”中,检查首选项的值,如果为false,则不执行任何操作。

  • 您可以取消注册您的应用以避免收到推送通知。您可以使用' GCMRegistrar.unregistrar()'来实现这一目标。