Class 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 the DeviceService 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 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()
    • Constructor Detail

      • PushClient

        public PushClient()
    • 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. The gcmSenderId 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 calling enable(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 becomes ConnectState.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