3

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?

guru_007
  • 473
  • 4
  • 16

1 Answers1

2

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.

Firebase

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.

José Pereda
  • 44,311
  • 7
  • 104
  • 132