Skip to content

Actions

Create Action

To create an action use builder method:

```java tab=”Java”
Action action = Action.builder(“my-custom-action”).build();

```kotlin tab="Kotlin"
val action = Action.builder("my-custom-action").build()

Add action data using addActionData(String key, String val) or addActionData(Map<String, String> map) - second one will add all the keys and values from parameter map. For the default GetSocial actions use one of ActionDataKeys constants to guarantee the default behavior. Also you can pass any custom data you want and handle it on the receiver side.

You can send any of predefined actions that will be handled by the SDK, for example to open Activity Feed with id “funny-stories” use:

```java tab=”Java”
Action action = Action.builder(ActionTypes.OPEN_ACTIVITY)
.addActionData(ActionDataKeys.OpenActivity.FEED_NAME, “funny-stories”)
.build();

```kotlin tab="Kotlin"
val action = Action.builder(ActionTypes.OPEN_ACTIVITY)
    .addActionData(ActionDataKeys.OpenActivity.FEED_NAME, "funny-stories")
    .build()

Currently you can attach actions to notifications or activity posts.

Handle Actions

```java tab=”Java”
boolean handleAction(Action action) {
switch (action.getType()) {
case ActionTypes.OPEN_PROFILE: // handle GetSocial action
showUserProfile(action.getData().get(ActionDataKeys.OpenProfile.USER_ID));
return true;

1
2
3
4
5
6
7
8
    case "try-campaign-mode": // handle custom action
        startCampaignMode();
        return true;

    default:
        // Other actions are handled by GetSocial.
        return false;
}

}
kotlin tab=”Kotlin”
fun handleAction(action: Action): Boolean {
when(action.type) {
ActionTypes.OPEN_PROFILE -> {
showUserProfile(action.data[ActionDataKeys.OpenProfile.USER_ID])
return true
}
“try-campaign-mode” -> { // handle custom action
startCampaignMode()
return true
} else -> {
// Other actions are handled by GetSocial.
return false
}
}
}
```

To handle custom actions use:

Tip

If you are not using GetSocial UI, we recommend to handle action by yourself - better user experience would be to react to actions.

GetSocial Actions

GetSocial SDK provides a list of predefined actions and processAction(...) method to process them. We use it internally in GetSocial UI. For you it may be helpful when building your custom UI.

```java tab=”Java”
GetSocial.processAction(Action action);

```kotlin tab="Kotlin"
GetSocial.processAction(action: Action)

Handled by GetSocial Core

  • ActionTypes.OPEN_URL: Will open a system web browser with provided URL. Required parameters:
    • ActionDataKeys.OpenUrl.URL - URL to open.
  • ActionTypes.ADD_FRIEND: Add user the the list of friends on Social Graph. Parameters:
    • ActionDataKeys.AddFriend.USER_ID - GetSocial user ID.
  • ActionTypes.CLAIM_PROMO_CODE: Claim a promo code. You can get the information about claiming via Webhook. We recommend you to override default behavior and call GetSocial.claimPromoCode to have a feedback about success inside the app.
    • ActionDataKeys.ClaimPromoCode.PROMO_CODE - promo code to claim.

Handled by GetSocial UI

  • ActionTypes.OPEN_INVITES: Will open Smart Invites view. Has no required parameters.
  • ActionTypes.OPEN_ACTIVITY: Will open Activity Feed. To open Activity Feed list provide following parameter:

    • ActionDataKeys.OpenActivity.FEED_NAME - Feed to Open. Use ActivitiesQuery.GLOBAL_FEED to open global feed.

    To open Activity Feed post itself and optionally scroll to the certain comment provide following parameters:
    - ActionDataKeys.OpenActivity.ACTIVITY_ID - Activity Feed post ID.
    - ActionDataKeys.OpenActivity.COMMENT_ID - Comment under that activity. Optional.

Not Handled

The following action is not handled by GetSocial:

  • ActionTypes.OPEN_PROFILE. Required parameters:
    • ActionDataKeys.OpenProfile.USER_ID - GetSocial user ID whose profile should be opened.

Give us your feedback! Was this article helpful?

😀 🙁