Sending push notification to Android from Java server using Urban airship

蹲街弑〆低调 提交于 2020-02-20 21:31:58

问题


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.

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 share any code or toturial
Thanks in advance


回答1:


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:

  • commons codec
  • commons logging
  • google gson
  • apache http client
  • apache http core

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);
    }



回答2:


urbanairship4j (available on Google Code) uses Google HTTP Java Client so works perfectly on any Java environment (inc. AppEngine, Android, etc).




回答3:


Try using the official Urban Airship Java API - This should help you get started...



来源:https://stackoverflow.com/questions/9622091/sending-push-notification-to-android-from-java-server-using-urban-airship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!