【问题标题】:Sending push notification to Android from Java server using Urban airship使用 Urban airship 从 Java 服务器向 Android 发送推送通知
【发布时间】:2023-03-30 16:17:02
【问题描述】:

我想使用 Urban airship 来发送 Push 通知到 Android。我可以从 Urban Airship 网站发送推送通知,但我不知道如何使用 urban Airship 网络服务 在 Java 应用程序 中发送消息。

我不想访问他们的网站并向任何 Android 设备发送消息,我只想让我的个人网站(使用 Java EE 开发)使用他们的服务并向 Android 设备发送消息。

请分享任何代码或toturial
提前致谢

【问题讨论】:

    标签: java android web-services push-notification urbanairship.com


    【解决方案1】:

    bitbucket 中的这个项目用 Java 封装了 Urban Airship REST API。

    https://bitbucket.org/sullis/urbanairship-java

    项目对以下库有外部依赖:

    • 公用编解码器
    • 公共日志记录
    • 谷歌 gson
    • apache http 客户端
    • apache http 核心

    下载并编译后,您可以使用以下代码发送推送通知:

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

    【讨论】:

    • 感谢@dhaval 的回复.. 我可以在不使用第三方库的情况下使用 Urban Airship
    • 实际列出的库是编译 api 源代码所必需的,否则您将无法使用它。第二种选择是编写自己的 java api,但最终还是会使用一些外部库来避免编写大量代码。
    【解决方案2】:

    urbanairship4j(可在 Google 代码上获得)使用 Google HTTP Java Client,因此可以在任何 Java 环境(包括 AppEngine、Android 等)上完美运行。

    【讨论】:

      【解决方案3】:

      尝试使用官方Urban Airship Java API - 这应该可以帮助您入门...

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多