Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling GCM push notification

I use GCM push notification for my Android app which is basically an instant messenger like Line/What's App. In my app, even after the user logs out, the push notification continue to happen. IN other words, I have no control over the notifications.

Ideally, I would like the notifications to stop when the user logs out of the app and resume after he logs in. Thanks in advance.

like image 346
Mikelbstek Avatar asked Jul 23 '26 01:07

Mikelbstek


2 Answers

You should use SharedPreferences.

You should have a preference that contain the value if the user should be alerted or not. Let's say, once a user logged out - set the preference value to false. Now,in your GCMIntentService in the onMessage method, check the value of the preference, if its false, just do nothing.

Have a look at this example:

How to use SharedPreferences in Android to store, fetch and edit values

like image 148
Givi Avatar answered Jul 25 '26 15:07

Givi


Call This Method GCMRegistrar.unregister(context); when the user signs out to stop receiving the push messages.

like image 23
scout Avatar answered Jul 25 '26 15:07

scout



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!