繁体   English   中英

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

[英]How to get push interactive notification with Urban Airship in Android?

我已将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')
}

根据官方文档 ,我在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。 根据官方文档,我发送了带有json的推:

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

但是我已经收到了带有“ Hello”文本且没有任何按钮的常规推送通知。

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

提前致谢。

关键字“类别”在Android上不正确。 它实际上正在寻找“ com.urbanairship.interactive_type”。 但是,您应该直接使用主编辑器,也可以直接使用push 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM