Interface PushNotificationsService
-
- All Known Implementing Classes:
IOSPushNotificationsService
public interface PushNotificationsService
Adds the ability for the application to receive remote push notifications.Example
String senderId = "abcd1234"; Services.get(PushNotificationsService.class).ifPresent(service -> { service.register(senderId); 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. } }); });
Android Configuration
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
.Also, make sure that you replace
$packageName
with the value of thepackage
attribute in themanifest
element that is defined at the top of your AndroidManifest.xml. You should have replaced the$packageName
string three times.<manifest ...> ... <permission android:name="$packageName.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="$packageName.permission.C2D_MESSAGE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> ... <application ...> <activity android:name="javafxports.android.FXActivity" android:label="SampleGluonApp" android:launchMode="singleTop" android:configChanges="orientation|screenSize"> <meta-data android:name="main.class" android:value="com.gluonhq.sample.SampleGluonApp"/> ... </activity> ... <receiver android:name="com.google.android.gms.gcm.GcmReceiver" 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="$packageName" /> </intent-filter> </receiver> <service android:name="com.gluonhq.impl.attach.plugins.android.PushNotificationJobService" android:permission="android.permission.BIND_JOB_SERVICE" android:exported="true" /> <service android:name="com.gluonhq.impl.attach.plugins.pushnotifications.android.PushGcmListenerService" android:exported="false"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> </intent-filter> </service> <service android:name="com.gluonhq.impl.attach.plugins.pushnotifications.android.PushInstanceIDListenerService" android:exported="false"> <intent-filter> <action android:name="com.google.android.gms.iid.InstanceID" /> </intent-filter> </service> <service android:name="com.gluonhq.impl.attach.plugins.pushnotifications.android.RegistrationIntentService" android:exported="false"> </service> <activity android:name="com.gluonhq.impl.attach.plugins.pushnotifications.android.PushNotificationActivity" android:parentActivityName="javafxports.android.FXActivity"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="javafxports.android.FXActivity"/> </activity> <meta-data android:name="com.google.android.gms.version" android:value="9452000"/> </application> </manifest>
iOS Configuration
You need to make sure that you set the
jfxmobile.ios.apsEnvironment
property in thebuild.gradle
of your project to eitherdevelopment
orproduction
, matching the configured provisioning profile.- Since:
- 3.2.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static java.util.Optional<PushNotificationsService>
create()
Returns an instance ofPushNotificationsService
.void
register(java.lang.String authorizedEntity)
Register the app for receiving push notifications.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(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.- Parameters:
authorizedEntity
- a string that matches the Sender ID of a GCM or FCM application
-
-