利用城市飞艇从Java服务器发送推送通知到Android [英] Sending push notification to Android from Java server using Urban airship
问题描述
我要使用城市飞艇提供的推送通知到Android 。我可以从城市飞艇的网站发送推送通知,但我不知道我怎么能在 Java应用程序使用的城市飞艇Web服务发送邮件。
I want to use Urban airship to deliver Push notification to Android. I can send Push notification from Urban Airship site but i don't know how can i send messages in Java application using urban Airship web service.
我不想去他们的网站和发送消息到任何Android设备,我只是希望我的个人网站(开发中的的Java EE )使用他们的服务,并发送消息到Android设备。
i don't want to go to their site and send message to any Android device i just wanted my personal website (developed in Java EE) to use their service and send messages to android devices.
PLZ分享任何的 code 或 toturial
在此先感谢
plz share any code or toturial
Thanks in advance
推荐答案
这个项目到位桶中封装了城市飞艇REST API在Java中。
This project in bitbucket encapsulates the Urban Airship REST API in Java.
https://bitbucket.org/sullis/urbanairship-java
该项目有外部依赖于以下库:
The project has external dependencies on following libraries:
- 在公共codeC
- 通用日志
- 的google GSON
- 的Apache HTTP客户端
- 的Apache HTTP核心
在下载和编译,你可以发送推送通知与下列code:
Once downloaded and compiled, you can send the push notification with following code:
public static void sendNotification() {
Push push = new Push();
push.setAliases(Arrays.asList("39901"));
// For Android
Android android = new Android();
android.setAlert("hi there");
push.setAndroid(android);
// For iOS
// APS aps = new APS();
// aps.setBadge(1);
// aps.setAlert("hi there");
// aps.setSound("default");
// aps.setData("additinoal data");
// push.setAps(aps);
UrbanAirshipClient uac = new UrbanAirshipClient("app key",
"master app key");
uac.sendPushNotifications(push);
}
这篇关于利用城市飞艇从Java服务器发送推送通知到Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!