Sending push notification to Android from Java server using Urban airship

淺唱寂寞╮ 提交于 2019-12-04 15:10:34

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

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

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

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