GcmPubSub methods have been integrated and simplified in the
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
/news after migration to FCM (note that the prefix "topics" is not
required in FCM).
The new methods
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.
// 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");
// Non-blocking methods. No need to use AsyncTask or background thread. FirebaseMessaging.getInstance().subscribeToTopic("mytopic"); FirebaseMessaging.getInstance().unsubscribeFromTopic("mytopic");