8

I've integrated Urban Airship SDK to my application on device with Android 4.2 (Jelly Bean). I've received general push-notifications. It's Ok. But I want to get interactive push-notification with button with "Save" label.

My dependencies from 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')
}

According to official documentation, I've added the following code in the onCreate() method in MyApplication class:

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

After that I've tried test push from my Urban Airship account:

EDIT:

I've used Urban Airship API v3. According to official documentation I've sent push with json:

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

But I've received general push-notification with "Hello" text and without any buttons.

What could be the problem and how to open some activity by click on the button in notification?

Thanks in advance.

eloibm
  • 899
  • 2
  • 11
  • 27
valerybodak
  • 4,195
  • 2
  • 42
  • 53
  • If I remember correctly, the "test push" composer doesn't have the ability to send interactive notifications. You will need to send the notification through the normal push composer. Or just send it through the API as documented here: http://docs.urbanairship.com/api/ua.html#interactive-notifications – Donato Perconti Jul 15 '15 at 17:18
  • Finally I've found the answer. I did not see this button "Save" in my notification because I have phone connected to PC via USB. http://stackoverflow.com/a/18477621/1225669 – valerybodak Jul 21 '15 at 08:34
  • Wow, fun issue. Does it show up if you try to manually expand the notification? – ralepinski Jul 23 '15 at 21:03
  • @ralepinski If I have phone connected to PC via USB and If I slide down by finger (Samsung Galaxy S4 Android 4.2 Jelly Bean) on notification then button "Save" is showing up. – valerybodak Jul 28 '15 at 07:41
  • One more issue. Interactive push notification works correctly only on my Samsung Galaxy S4 (Android 4.2.2 Jelly Bean). But "Save" button NOT visible by default on ZTE Nubia z5 mini (Android 4.4.2 KitKat). Only after slide down by notification my "Save" button becomes visible. HTC desire 600 (Android 4.1.2) - "Save" button does not appear at all unfortunately. – valerybodak Jul 30 '15 at 07:35

1 Answers1

0

The key "category" is not the correct on Android. Its actually looking for "com.urbanairship.interactive_type". However you should be either using the main composer or the push API directly.

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/

But with your apps credentials for <APP_KEY>:<MASTER_SECRET>

See http://docs.urbanairship.com/api/ua.html#interactive-api for more details.

ralepinski
  • 1,756
  • 8
  • 15
  • Ok. I will get back to you. One more question. Should I create custom NotificationFactory for showing button "Save" in notification? – valerybodak Jul 20 '15 at 11:45
  • No. It doesn't work for me. I've received general notification without any buttons. – valerybodak Jul 20 '15 at 14:26
  • If you are using a custom notification factory then you have to call `builder.extend(createNotificationActionsExtender(message, notificationId));` to get notifications to work. – ralepinski Jul 23 '15 at 21:00