Turn off GCM Notifications

680 views Asked by At

I am developing the app where I'm using GCM. I have taken sample GCM example from google samples from github and implemented every thing is fine,But i want to TURNOFF the GCM notifications. I have specified GCM notification turn ON/OFF in another Activity using toggle button.when i click on toggle button it should work accordingly

I found subscribeTopics method in RegistrationIntentService.java

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 

To TURN OFF Notifications

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

I'm unable to call UnSubscribeTopics method.Because that method is in RegistrationIntentService.java which extends Intentservice.How can i call method '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.

Any help???

Thanks in advance.

1

There are 1 answers

0
Android Enthusiast On

You have two options to do that:

  • 'SharedPreferences' you should have a preference that contain the value if the user should be notified or not. You may set the preference value to 'false'. In your 'GCMIntentService', check the value of the preference, if it's false, do nothing.

  • You may unregister your app to avoid receiving push notifications. You can use 'GCMRegistrar.unregistrar()' to make this happen.