Interface PushNotificationsService
- All Known Implementing Classes:
AndroidPushNotificationsService
,IOSPushNotificationsService
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();
});
Requirements
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="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>
...
<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.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 the
Entitlements
section to either development
or production
.
- Since:
- 3.2.0
-
Property Summary
TypePropertyDescriptionjavafx.beans.property.ReadOnlyStringProperty
The unique registration token that can be passed to the server, so the app can receive push notifications -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<PushNotificationsService>
create()
Returns an instance ofPushNotificationsService
.void
register()
Register the app for receiving push notifications.void
Deprecated.void
setAppIconBadgeNumber
(int badgeNumber) On iOS, set the number showing as the badge of the app icon on the Home screen.javafx.beans.property.ReadOnlyStringProperty
The unique registration token that can be passed to the server, so the app can receive push notifications
-
Property Details
-
token
javafx.beans.property.ReadOnlyStringProperty tokenPropertyThe unique registration token that can be passed to the server, so the app can receive push notifications
-
-
Method Details
-
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 -
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.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
-
setAppIconBadgeNumber
void setAppIconBadgeNumber(int badgeNumber) On iOS, set the number showing as the badge of the app icon on the Home screen. Set number to 0 to hide the badge number. On Android, override the default number of notifications displayed in the popup that can be shown from the app icon. Set 0 to use the default notification counter. Important notes: - there is no track of the current badge number that the icon might have - when the push notification is read, there is no automatic handling of decreasing the badge number So it is up to the developer to handle this number properly.- Parameters:
badgeNumber
- the number that will show up in the app icon badge, or 0 to hide it. The default value is 0.
-