Am I new to Android Development using javafx ,and I have created a sample app using javafx (using FXports and gluon plugin ).
So Far apps works good in the android phone.
But, I want to use android APIs in my javafx project and create a push Notification that appears on startup of the app.
How Do I accomplish this task?

- 473
- 4
- 16
1 Answers
Have a look at the Gluon's open source library Charm Down. There is a plugin for Push Notifications for both Android and iOS.
If you have already created a project with the Gluon plugin, you can add this plugin:
jfxmobile {
downConfig {
version = '3.2.4'
plugins 'display', 'lifecycle', 'push-notifications', 'statusbar', 'storage'
}
...
}
As for its use, see the docs here: you will find what steps are required to use the service.
To enable push notifications on Android, go to Firebase, sign up or sign in, create a new project. To the right of the Overview option, click the settings button, select project settings, and select the Cloud Messaging tab.
Retrieve the Sender ID and add it to your app. The main application postInit
method is a good place for it:
@Override
public void postInit(Scene scene) {
Services.get(PushNotificationsService.class).ifPresent(service -> {
service.register(435XXXXXX);
service.tokenProperty.addListener((obs, ov, nv) -> {
System.out.println("Device token: " + nv);
});
});
}
Before deploying, you need to add the required configuration referred in the docs to the AndroidManifest file.
Finally deploy to your device, and check (with adb logcat
) that it prints out its device token, you will need it, and the Server Key from Firebase, to be able to send a push notification to that device.

- 44,311
- 7
- 104
- 132
-
what for 'PushNotificationsService.class' is used for? – guru_007 Mar 03 '17 at 19:06
-
1Add the plugin to the build.gradle file, reload the project so it downloads and includes its jar. Then you will be able to import the `PushNotificationsService` class. – José Pereda Mar 03 '17 at 19:12
-
how about LocalNotificationsServices.class does it works or Not! @jose Perada – guru_007 Mar 04 '17 at 13:17
-
Why not? You can try it as well. Check the documentation for that plugin – José Pereda Mar 04 '17 at 13:19
-
i have tried LocalNotficationServices.class its Not working – guru_007 Mar 04 '17 at 14:00
-
Create a new question for this, posting the relevant code you have tried. – José Pereda Mar 04 '17 at 14:01
-
here's the new Question [link](http://stackoverflow.com/questions/42598628/gluon-mobile-localnotificationsservices-class-not-working) – guru_007 Mar 04 '17 at 16:55