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

val*_*dak 8 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')
}
Run Code Online (Sandbox Code Playgroud)

根据官方文档,我onCreate()MyApplication类中的方法中添加了以下代码:

@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);
}
Run Code Online (Sandbox Code Playgroud)

之后我尝试了我的Urban Airship帐户的测试推送:

编辑:

我使用过Urban Airship API v3.根据官方文档,我发送了json推送:

{ 
  "audience": {
    "named_user": "2971" 
  }, 
  "device_types":["android"], 
  "notification": { 
    "android": { 
      "alert": "Hello",
      "extra": {
        "EEID": "2971",
        "DATE": "20150601"
      },
      "interactive": { 
        "type": "save"
      } 
    } 
  } 
}
Run Code Online (Sandbox Code Playgroud)

但是我收到了"Hello"文本和没有任何按钮的一般推送通知.

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

提前致谢.

ral*_*ski 0

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/
Run Code Online (Sandbox Code Playgroud)

但凭借您的应用程序凭据<APP_KEY>:<MASTER_SECRET>

请参阅http://docs.urbanairship.com/api/ua.html#interactive-api了解更多详细信息。