- java.lang.Object
-
- com.gluonhq.cloudlink.client.push.PushClient
-
public class PushClient extends Object
The PushClient handles the activation of push notifications for the Gluon Mobile application. Upon enabling it, the device will be registered at the correct push notifications service for the platform where the device is running on. For Android devices, this is Google Cloud Messaging (GCM) or Firebase Cloud Messaging (FCM); for iOS devices, this is the Apple Push Notification service (APNs).
Note: The PushClient uses the
PushNotificationsService
for handling the platform specific details of push notifications. It also depends on theDeviceService
to get a handle to the unique identifier of the device for the Gluon Mobile application. Therefore, make sure that both the push-notifications plugin and the device plugin have been enabled in your Gluon Mobile application build configuration:<dependency> <groupId>com.gluonhq.attach</groupId> <artifactId>device</artifactId> <version>${attach.version}</version> </dependency> <dependency> <groupId>com.gluonhq.attach</groupId> <artifactId>push-notifications</artifactId> <version>${attach.version}</version> </dependency> ... <plugin> <groupId>com.gluonhq</groupId> <artifactId>client-maven-plugin</artifactId> <version>${client.plugin.version}</version> <configuration> <attachList> <list>device</list> <list>push-notifications</list> </attachList> </configuration> </plugin>
-
-
Property Summary
Properties Type Property Description ReadOnlyBooleanProperty
enabled
This read-only property can be listened to, to detect if the current device is ready for receiving push notifications or for subscribing to specific topics.
-
Constructor Summary
Constructors Constructor Description PushClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
enable(String gcmSenderId)
Enable push notifications for the Gluon Mobile application.ReadOnlyBooleanProperty
enabledProperty()
This read-only property can be listened to, to detect if the current device is ready for receiving push notifications or for subscribing to specific topics.boolean
isEnabled()
Check if the current device is correctly registered for receiving push notifications.GluonObservableObject<TopicSubscription>
subscribe(String topic)
Subscribe the current device to the specified topic.GluonObservableObject<Void>
unsubscribe(String topic)
Unsubscribe the current device from the specified topic.
-
-
-
Property Detail
-
enabled
public ReadOnlyBooleanProperty enabledProperty
This read-only property can be listened to, to detect if the current device is ready for receiving push notifications or for subscribing to specific topics.- See Also:
isEnabled()
-
-
Method Detail
-
enable
public void enable(String gcmSenderId)
Enable push notifications for the Gluon Mobile application. This will make sure that the application is correctly registered for use with push notifications on the running platform. ThegcmSenderId
is the Sender ID of your GCM or FCM application. iOS devices don't need any specific parameters because they will be setup correctly when building the iOS ipa application bundle.- Parameters:
gcmSenderId
- the Sender ID of the Google Cloud Messaging application
-
isEnabled
public boolean isEnabled()
Check if the current device is correctly registered for receiving push notifications. When this is true, the device will be able to receive a push notification for this application. It can also start subscribing to specific topics.- Returns:
true
if the current device can receive push notifications,false
otherwise.
-
enabledProperty
public ReadOnlyBooleanProperty enabledProperty()
This read-only property can be listened to, to detect if the current device is ready for receiving push notifications or for subscribing to specific topics.- See Also:
isEnabled()
-
subscribe
public GluonObservableObject<TopicSubscription> subscribe(String topic) throws IllegalStateException
Subscribe the current device to the specified topic. Subscribing to an already subscribed topic will just keep the existing subscription. You must first enable push notifications by callingenable(String)
before you can subscribe the device to a topic.- Parameters:
topic
- The name of the topic to subscribe to.- Returns:
- A GluonObservableObject that can be used to determine if subscribing to the topic was successful.
- Throws:
IllegalStateException
- when the process of enabling push notifications for this device is not yet fully completed
-
unsubscribe
public GluonObservableObject<Void> unsubscribe(String topic) throws IllegalStateException
Unsubscribe the current device from the specified topic. Unsubscribing from a topic when there is no current subscription will do nothing. One can listen to the state of the returned GluonObservableObject. When the state becomesConnectState.REMOVED
, unsubscribing from the topic was successful.- Parameters:
topic
- The name of the topic to unsubscribe from.- Returns:
- A GluonObservableObject that can be used to determine if unsubscribing was successful.
- Throws:
IllegalStateException
- when the process of enabling push notifications for this device is not yet fully completed
-
-