且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用javafx在android中创建推送通知

更新时间:2023-02-26 22:55:10

查看Gluon的开源



检索发件人ID并将其添加到您的应用中。主应用程序 postInit 方法适合它:

  @覆盖
public void postInit(场景场景){
Services.get(PushNotificationsService.class).ifPresent(service - > {
service.register(435XXXXXX);
service。 tokenProperty.addListener((obs,ov,nv) - > {
System.out.println(Device token:+ nv);
});
});
}

在部署之前,您需要将文档中引用的必需配置添加到AndroidManifest文件。



最后部署到您的设备,并检查(使用 adb logcat )打印出其设备令牌,您需要它,以及来自Firebase的服务器密钥,以便能够向该设备发送推送通知。


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?

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.