This class is deprecated.
GCM is deprecated and replaced by Firebase Cloud Messaging (FCM). See the FCM migration guide
for details on how to migrate to FCM.
GcmPubSub provides a publish-subscribe model for sending GCM topic messages.
An app can subscribe to different topics defined by the developer. The app server can then send messages to the subscribed devices without having to maintain topic-subscribers mapping. Topics do not need to be explicitly created before subscribing or publishing—they are automatically created when publishing or subscribing.
String topic = "/topics/myTopic";
String registrationToken = InstanceID.getInstance(context)
.getToken(SENDER_ID, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
GcmPubSub.getInstance(context).subscribe(registrationToken, topic, null);
// Messages published to the topic will be received as regular GCM messages
// with 'from' set to "/topics/myTopic"
To publish to a topic, see GCM server documentation.
| synchronized static GcmPubSub |
getInstance(Context
context)
This method is deprecated. GCM is deprecated and replaced by FCM. See the
FCM
migration guide for details on how to migrate to FCM.
|
| void |
subscribe(String
registrationToken, String topic,
Bundle
extras)
This method is deprecated. GCM is deprecated and replaced by FCM. See the
FCM
migration guide for details on how to migrate to FCM.
|
| void |
unsubscribe(String
registrationToken, String topic)
This method is deprecated. GCM is deprecated and replaced by FCM. See the
FCM
migration guide for details on how to migrate to FCM.
|
This method is deprecated.
GCM is deprecated and replaced by FCM. See the FCM migration
guide for details on how to migrate to FCM.
Returns an instance of GCM PubSub.
This method is deprecated.
GCM is deprecated and replaced by FCM. See the FCM migration
guide for details on how to migrate to FCM.
Subscribes an app instance to a topic, enabling it to receive messages sent to that topic.
The topic sender must be authorized to send messages to the app instance. To
authorize it, call
getToken(String, String) with the sender ID and
INSTANCE_ID_SCOPE
Do not call this function on the main thread.
| registrationToken | InstanceID
token that authorizes topic sender to send messages to the app instance. |
|---|---|
| topic | developer defined topic name. Must match the following regular expression: "/topics/[a-zA-Z0-9-_.~%]{1,900}". |
| extras | (optional) additional information. |
| IOException | if the request fails. |
|---|
This method is deprecated.
GCM is deprecated and replaced by FCM. See the FCM migration
guide for details on how to migrate to FCM.
Unsubscribes an app instance from a topic, stopping it from receiving any further messages sent to that topic.
Do not call this function on the main thread.
| registrationToken | InstanceID
token for the same sender and scope that was previously used for subscribing to the
topic. |
|---|---|
| topic | from which to stop receiving messages. |
| IOException | if the request fails. |
|---|