如何在Android中使用Urban Airship实现互动式通知?

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

我从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帐户中进行testing:

编辑:

我使用了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”文本,没有任何button。

可能是什么问题,以及如何通过点击通知button打开一些活动?

提前致谢。

Solutions Collecting From Web of "如何在Android中使用Urban Airship实现互动式通知?"

关键“类别”在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