2

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.

Mikelbstek
  • 61
  • 2
  • 10
  • You should share a bit how you implement the push notifications, What you have tried already to make them stop and didn't work. – Raanan Feb 18 '13 at 09:21

4 Answers4

7

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

Community
  • 1
  • 1
Givi
  • 3,283
  • 4
  • 20
  • 23
5

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

Ashish Kakkad
  • 23,586
  • 12
  • 103
  • 136
scout
  • 307
  • 1
  • 3
  • 8
  • Intent unregIntent = new Intent("com.google.android.c2dm.intent.UNREGISTER"); unregIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0)); startService(unregIntent); I saw this code from google to unregister my device, Any way how to use this – Mikelbstek Feb 18 '13 at 10:50
1

You have to unregister your app to avoid receiving further push notifications. You can use GCMRegistrar.unregistrar() to make this happen.

Khawar Raza
  • 15,870
  • 24
  • 70
  • 127
0

As Google unregister() method was deprecated, instead use the InstanceID.deleteInstanceID().

peter.bartos
  • 11,855
  • 3
  • 51
  • 62