使用javafx在android中创建推送通知 [英] creating push notifications in android using javafx

查看:343
本文介绍了使用javafx在android中创建推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是使用javafx进行Android开发的新手,我使用 javafx (使用FXports和gluon插件)创建了一个示例应用程序。
远程应用程序在Android手机中运行良好。<但是,我想在我的javafx项目中使用android API并创建一个在应用程序启动时出现的推送通知。
如何完成此任务?

解决方案

查看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.

这篇关于使用javafx在android中创建推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆