Interface PushNotificationsService
-
- All Known Implementing Classes:
AndroidPushNotificationsService
,IOSPushNotificationsService
public interface PushNotificationsService
Adds the ability for the application to receive remote push notifications.Example
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. } }); service.register(); });
Android Configuration
To enable push notifications on android, an existing Google Firebase project is required. Copy the
google-services.json
file into your project'ssrc/android/resources
folder.The following
permissions
,services
andreceiver
need to be added to the android manifest configuration file to make push notifications work on android. The main activity also requires the attributeandroid:launchMode
with valuesingleTop
.<manifest ...> ... <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <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" android:configChanges="orientation|keyboardHidden" android:launchMode="singleTop"> ... </activity> ... <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND" > <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <category android:name="${applicationId}" /> </intent-filter> </receiver> <service android:name="com.gluonhq.helloandroid.PushFcmMessagingService"> <intent-filter> <action android:name="com.google.firebase.MESSAGING_EVENT" /> </intent-filter> </service> <service android:name="com.gluonhq.helloandroid.PushInstanceIdService"> <intent-filter> <action android:name="com.google.firebase.INSTANCE_ID_EVENT" /> </intent-filter> </service> <service android:name="com.google.firebase.components.ComponentDiscoveryService"> <meta-data android:name="com.google.firebase.components:com.google.firebase.iid.Registrar" android:value="com.google.firebase.components.ComponentRegistrar"/> </service> <service android:name="com.gluonhq.helloandroid.PushNotificationJobService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true" /> <activity android:name="com.gluonhq.helloandroid.PushNotificationActivity" android:parentActivityName="com.gluonhq.helloandroid.MainActivity"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.gluonhq.helloandroid.MainActivity"/> </activity> </application> </manifest>
iOS Configuration
You need to use a Provisioning Profile that defines the
aps-environment
property in theEntitlements
section to eitherdevelopment
orproduction
.- Since:
- 3.2.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description static java.util.Optional<PushNotificationsService>
create()
Returns an instance ofPushNotificationsService
.void
register()
Register the app for receiving push notifications.void
register(java.lang.String authorizedEntity)
Deprecated.javafx.beans.property.ReadOnlyStringProperty
tokenProperty()
The unique registration token that can be passed to the server, so the app can receive push notifications
-
-
-
Method Detail
-
create
static java.util.Optional<PushNotificationsService> create()
Returns an instance ofPushNotificationsService
.- Returns:
- An instance of
PushNotificationsService
.
-
tokenProperty
javafx.beans.property.ReadOnlyStringProperty tokenProperty()
The unique registration token that can be passed to the server, so the app can receive push notifications- Returns:
- 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.- Since:
- 4.0.10
-
register
@Deprecated void register(java.lang.String authorizedEntity)
Deprecated.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.- Parameters:
authorizedEntity
- a string that matches the Sender ID of a GCM or FCM application
-
-