Interface PushNotificationsService

  • All Known Implementing Classes:
    AndroidPushNotificationsService, IOSPushNotificationsService

    public interface PushNotificationsService
    Adds the ability for the application to receive remote push notifications.


     PushNotificationsService.create().ifPresent(service -> {
           service.tokenProperty.addListener((observable, oldValue, newValue) -> {
               if (newValue != null) {
                   String deviceToken = newValue;
                   // This deviceToken can be used to send push notifications to this device by calling
                   // the appropriate server API for the platform. Usually, this token is sent to a server
                   // where the push notifications are created and sent out.


    The service requires the following changes on Android and iOS.

    However, these are handled automatically by the GluonFX plugin, when used.

    Android Configuration

    To enable push notifications on android, an existing Google Firebase project is required. Copy the google-services.json file into your project's src/android/resources folder.

    The following permissions, services and receiver need to be added to the android manifest configuration file to make push notifications work on android. The main activity also requires the attribute android:launchMode with value singleTop.

     <manifest ...>
        <uses-permission android:name="" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
        <application ...>
          <activity android:name="com.gluonhq.helloandroid.MainActivity"
          <service android:name="com.gluonhq.helloandroid.PushFcmMessagingService">
              <action android:name="" />
          <service android:name="com.gluonhq.helloandroid.PushNotificationJobService"
                   android:exported="true" />
          <activity android:name="com.gluonhq.helloandroid.PushNotificationActivity"
                <meta-data android:name=""

    iOS Configuration

    You need to use a Provisioning Profile that defines the aps-environment property in the Entitlements section to either development or production.

    • Method Detail

      • tokenProperty tokenProperty()
        The unique registration token that can be passed to the server, so the app can receive push notifications
        a ReadOnlyStringProperty with a unique token
      • register

        void register()
        Register the app for receiving push notifications. On iOS this will trigger a confirmation dialog that must be accepted by the user.
      • register

        void register​(java.lang.String authorizedEntity)
        Register the app for receiving push notifications. On iOS this will trigger a confirmation dialog that must be accepted by the user. For Android, you need to pass in the authorizedEntity value that matches the Sender ID of your Google Cloud Messaging or Firebase Cloud Messaging application.
        authorizedEntity - a string that matches the Sender ID of a GCM or FCM application