As of April 10, 2018, Google has deprecated GCM. The GCM server and client APIs are deprecated and will be removed as soon as April 11, 2019. Migrate GCM apps to Firebase Cloud Messaging (FCM), which inherits the reliable and scalable GCM infrastructure, plus many new features. See the migration guide to learn more.

Update the usage of GcmPubSub

GcmPubSub methods have been integrated and simplified in the FirebaseMessaging class. To subscribe new devices to your existing GCM topics, use the new FirebaseMessaging.subscribeToTopic method. Devices already subscribed to a topic prior to migration will continue to receive messages. For example, a device subscribed to /topics/news in GCM will continue to receive messages sent to /news after migration to FCM (note that the prefix "topics" is not required in FCM).

The new methods subscribeToTopic(topic-name)and unsubscribeFromTopic(topic-name)include the following changes:

  • Asynchronous execution: the method doesn't block the current thread; instead, the operation is automatically performed in a background thread. You won't need to manage threads as you did for GCM.

  • Auto retry logic: the operation is stored and automatically retried in case of connectivity issues.

  • Implicit token: the previously required token is now automatically created, using the sender ID specified by the Firebase Project.

Before

// Blocking methods. Execute them inside an AsyncTask or background thread.
GcmPubSub.getInstance(context).subscribe("token", "/topics/mytopic", null /* extras bundle */);
GcmPubSub.getInstance(context).unsubscribe("token", "/topics/mytopic");

After

// Non-blocking methods. No need to use AsyncTask or background thread.
FirebaseMessaging.getInstance().subscribeToTopic("mytopic");
FirebaseMessaging.getInstance().unsubscribeToTopic("mytopic");

Send feedback about...

Cloud Messaging
Cloud Messaging