Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unregister on new Google Cloud Messaging

I'm using the new google cloud messaging

(GoogleCloudMessaging gcm =
           GoogleCloudMessaging.getInstance (context);)

I am following this example, which is very good and works perfectly:

https://github.com/commonsguy/cw-omnibus/tree/master/Push/GCMClient2

With this example I can register in the GCM, but I tried unsuccessfully to unregister.

in the documentation indicates that you should use the following intent:

com.google.android.c2dm.intent.UNREGISTER

And use it as follows:

    

 Intent unregIntent = new Intent ("com.google.android.c2dm.intent.UNREGISTER");
     unregIntent.putExtra ("app", PendingIntent.getBroadcast (this, 0, new Intent (), 0));
     StartService (unregIntent);

not working ...

As I said, the register works fine, but do not know how to unregister.

I have to do more than the intent? What am I doing wrong?

I appreciate any help

Thanks and regards

like image 531
Sergio76 Avatar asked Jul 18 '13 11:07

Sergio76


1 Answers

If you are using the new GoogleCloudMessaging class, you don't need to use the com.google.android.c2dm.intent.UNREGISTER intent. Simply use GoogleCloudMessaging.unregister().

public void unregister ()

Unregister the application. Calling unregister() stops any messages from the server. This is a blocking call—you shouldn't call it from the UI thread. You should rarely (if ever) need to call this method. Not only is it expensive in terms of resources, but it invalidates your registration ID, which should never change unnecessarily. A better approach is to simply have your server stop sending messages. Only use unregister if you want your application to stop using GCM permanently, or you have a compelling reason to recycle your registration ID. Throws IOException if we can't connect to server to unregister.

like image 98
Eran Avatar answered Nov 15 '22 21:11

Eran