android - 如何在 Android 中使用 Urban Airship 获取推送交互通知?

标签 android push-notification urbanairship.com

我已经将 Urban Airship SDK 集成到我在 Android 4.2 (Jelly Bean) 设备上的应用程序中。我收到了一般推送通知。没关系。但我想通过带有“保存”标签的按钮获得交互式推送通知。

我来自 build.gradle 的依赖项:

dependencies {
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.android.gms:play-services:+'

    compile project (':urbanairship-lib-6.1.1')
    compile 'com.android.support:support-v4:22.2.0'

    // Recommended for in-app messaging
    compile 'com.android.support:cardview-v7:22.2.0'

    // Recommended for location services
    compile 'com.google.android.gms:play-services-location:7.5.0'

    // Required for Android (GCM) push notifications
    compile 'com.google.android.gms:play-services-gcm:7.5.0'

    compile files('libs/commons-io-2.4.jar')
    compile files('libs/FlurryAnalytics-4.1.0.jar')
    compile files('libs/nineoldandroids-2.4.0.jar')
}

根据 official documentation ,我在 MyApplication 类的 onCreate() 方法中添加了以下代码:

@Override
public void onCreate() {
    AirshipConfigOptions options = new AirshipConfigOptions();
    options.developmentAppKey = "sdgsdgsdhsdh";
    options.developmentAppSecret = "sdhsdhsdhsdhsh";
    options.productionAppKey = "Your Production App Key";
    options.productionAppSecret = "Your Production App Secret";
    options.inProduction = false;

    options.gcmSender = "11111111";

    UAirship.takeOff(this, options);

    NotificationActionButton hiButtonAction = new NotificationActionButton.Builder("btnSave")
            .setLabel(R.string.save)
            .setPerformsInForeground(true)
            .build();

    // Define the group
    NotificationActionButtonGroup buttonGroup = new NotificationActionButtonGroup.Builder()
            .addNotificationActionButton(hiButtonAction)
            .build();

    // Add the custom group
    UAirship.shared().getPushManager().addNotificationActionButtonGroup("save", buttonGroup);

    UAirship.shared().getPushManager().setUserNotificationsEnabled(true);

    UAirship.shared().getPushManager().setPushEnabled(true);
}

之后,我尝试从我的 Urban Airship 帐户进行测试推送:

编辑:

我使用过 Urban Airship API v3。根据official documentation我已经用 json 发送了推送:

{ 
  "audience": {
    "named_user": "2971" 
  }, 
  "device_types":["android"], 
  "notification": { 
    "android": { 
      "alert": "Hello",
      "extra": {
        "EEID": "2971",
        "DATE": "20150601"
      },
      "interactive": { 
        "type": "save"
      } 
    } 
  } 
}

但是我收到了带有“你好”文本但没有任何按钮的一般推送通知。

可能是什么问题以及如何通过单击通知中的按钮来打开某些 Activity ?

提前致谢。

最佳答案

“类别”键在 Android 上不正确。它实际上是在寻找“com.urbanairship.interactive_type”。但是,您应该直接使用主 Composer 或推送 API。

curl -v -X POST -u <APP_KEY>:<MASTER_SECRET> -H "Content-type: application/json" -H "Accept: application/vnd.urbanairship+json; version=3;" --data '{
    "audience":"ALL",
    "device_types":["android"],
    "notification": {
        "android": {
            "alert": "Hello",
            "interactive": {
                "type": "save"
            }
        }
    }
}'  https://go.urbanairship.com/api/push/

但是使用您的应用凭据 <APP_KEY>:<MASTER_SECRET>

参见 http://docs.urbanairship.com/api/ua.html#interactive-api了解更多详情。

关于android - 如何在 Android 中使用 Urban Airship 获取推送交互通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31429077/

相关文章:

java - Android编程中如何获取当前位置

ios - 我们可以从 iOS 设备向 APNs 发送推送通知吗?

android - Urban-airship + Facebook cordova 插件 android-support-v4 冲突

android - 适用于 Android 的 MQTT 代理

javascript - HTML5 DeviceAPI 不工作(返回 null)

android - 通过 Java 连接 GCM 时获取 JSON 异常

ios - Urban Airship iOS 在 UIWebView 上显示消息正文

android - Urban Airship 生产与发展项目名称

android - 从服务启动 View ?

ios - PushKit:我们可以在不使用 VoiP 的情况下在聊天应用程序中使用推送工具包(VoiP 推送)吗