Skip to content

Working with Activity Feed Posts

Post your first activity

To post an activity to global activity feed you can use code below:

  1. Create ActivityPostContent object:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    String buttonTitle = "Get extra life!";
    String buttonAction = "get-extra-life";
    Bitmap activityImage = ...;// load image here
    
    ActivityPostContent postContent = ActivityPostContent
            .createBuilderWithText("Hello, this is my first post!")
            .withButton(buttonTitle, buttonAction)
            .withMediaAttachment(MediaAttachment.image(activityImage))
            .build();
    

    Recommended Image Size

    Recommended image resolution is 1024x768px. Bigger images will be downscaled.

  2. Post an activity to Global Feed:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    GetSocial.postActivityToGlobalFeed(postContent, new Callback<ActivityPost>() {
        @Override
        public void onSuccess(ActivityPost activityPost) {
            Log.i("GetSocial", "You activity was successfully posted!");
        }
    
        @Override
        public void onFailure(GetSocialException e) {
            Log.e("GetSocial", "Posting failed, error: " + e.getMessage());
        }
    });
    

Custom Activity Feed

To post an activity to custom feed, just pass feed name as a parameter to postActivityToFeed method:

1
GetSocial.postActivityToFeed("level-42", postContent, callback);

Action Buttons

Action button can be added to your activity or announcement. It is a simple, but very powerful part of Activity Feed functionality. See how to post activity with button:

  1. Create post content with Action Button:

    1
    2
    3
    4
    5
    6
    7
    String buttonTitle = "Look now!";
    String buttonAction = "look-profile";
    
    ActivityPostContent contentWithButton = ActivityPostContent
            .createBuilderWithText("Look at my cool profile!")
            .withButton(buttonTitle, buttonAction)
            .build();
    
  2. Post to a selected feed:

    1
    GetSocial.postActivityToGlobalFeed(contentWithButton, callback);
    

In this case you will post as a user.
If you want to post as the App, use dashboard - simple activity, or post an Announcement.

Field Type Value
buttonTitle String A text that will be displayed on button
buttonAction String Your internal action, that you know how to deal with. Our SDK doesn’t know anything about your actions, we just attach them to buttons.

If you don’t use GetSocial UI, you should display and handle your button with own code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
if (post.hasButton()) {
    //show button and set it text and action
    actionButton.setText(post.getButtonTitle());
    actionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String action = post.getButtonAction();
            // Handle your action on button click.
            // processAction(action, post);
        }
    });
} else {
    //hide a button
}

If you’re using GetSocial UI, you life is easier, all you need is set ActionButtonListener:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
GetSocialUi.createGlobalActivityFeedView()
    .setButtonActionListener(new ActionButtonListener() {
        @Override
        public void onButtonClicked(String buttonAction, ActivityPost activityPost) {
            // Handle you action on button click.
            // processAction(buttonAction, activityPost);
        }
    })
    .show();
````

Example of your `processAction` method:

```java
void processAction(String action, ActivityPost post) {
    switch (action) {
        case "look-profile":
            showUserProfile(post.getAuthor());
            break;

        case "try-campaign-mode":
            startCampaignGame();
            break;

        default:
            //We don't know how to handle other actions;
            break;
    }
}

Post Activity With Mentions

To mention user in the Activity Feed post insert @12345678, where 12345678 is the GetSocial user Id you want to mention:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
PublicUser user = ...;
String contentText = String.format("Hello, @%s. How are you?", user.getId());
ActivityPostContent postContent = ActivityPostContent
                .createBuilderWithText(contentText)
                .build();
GetSocial.postActivityToGlobalFeed(postContent, callback);
````

To mention the application use `"@app"` in the post text:

```java hl_lines="2"
ActivityPostContent postContent = ActivityPostContent
                .createBuilderWithText("Hey, @app. When new features will be available?")
                .build();
GetSocial.postActivityToGlobalFeed(postContent, callback);

On the backend, when activity is posted, @id is replaced with the display name of the user or app name.

To check if activity has any mentions in content, use post.getMentions() method. Mention object contains id of user, start and end index of mention in content text, so you can handle interactions with mentions.

If you’re using GetSocial UI, to handle click on mention in Activity Feed, set the MentionClickListener:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
GetSocialUi.createGlobalActivityFeedView()
    .setMentionClickListener(new MentionClickListener() {
        @Override
        public void onMentionClicked(String mention) {
            if (mention.equals(MentionClickListener.APP_SHORTCUT)) {
                // Handle click on the app mention
            } else {
                String userId = mention;
                // Handle click on the user mention
            }
        }
    })
    .show();

Post Activity With Tags

To post activity with tag, just insert #mytag - where mytag is a tag you want to post:

1
2
3
4
5
6
String contentText = "Like my #cat photo!";
ActivityPostContent postContent = ActivityPostContent
                .createBuilderWithText(contentText)
                .withMediaAttachment(MediaAttachment.image(myCatPhotoImage))
                .build();
GetSocial.postActivityToGlobalFeed(postContent, callback);

Tags may go one by one without spaces:

1
String contentText = "#get#social with your friends!"

The activity with text as above will have two tags #get and #social.

Warning

Tag should contain at least one letter, consist of letters, numbers and _, and be not longer than 80 symbols, otherwise it won’t be treated as tag on the backend side.

If you’re using GetSocial UI, to handle click on the tag use TagClickListener:

1
2
3
4
5
6
7
8
GetSocialUi.createGlobalActivityFeedView()
    .setTagClickListener(new TagClickListener() {
        @Override
        public void onTagClicked(String tag) {
            handleTagClick(tag);
        }
    })
    .show();

For example, on tag click you can open Activity Feed filtered by that tag using setFilterByTags as described below.

Post from GetSocial UI

On the list of posts, there is an input to post something. Only text posts are supported from GetSocial UI, to post images or buttons from SDK, use code above.

List Activities

To get a list of posted activities in global feed:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
ActivitiesQuery query = ActivitiesQuery.postsForGlobalFeed();
GetSocial.getActivities(query, new Callback<List<ActivityPost>>() {
    @Override
    public void onSuccess(List<ActivityPost> activityPosts) {
        Log.i("GetSocial", "Successfully retrieved activities list");
        showActivities(activityPosts);
    }

    @Override
    public void onFailure(GetSocialException e) {
        Log.e("GetSocial", "Failed to get activities, error: " + e.getMessage());
    }
});

Pagination

ActivitiesQuery class supports pagination. By default, it retrieves first posts with limit=10.
Fox example, if you have a list of activities and want to get 15 older activities:

1
2
3
4
5
ActivityPost oldestActivity = yourActivities.get(yourActivities.size() - 1);
ActivitiesQuery query = ActivitiesQuery
        .postsForGlobalFeed()
        .withFilter(ActivitiesQuery.Filter.OLDER, oldestActivity.getId())
        .withLimit(15);

In the same way you can get newer activities, using ActivitiesQuery.Filter.NEWER:

1
2
3
4
5
ActivityPost newestActivity = yourActivities.get(0);
ActivitiesQuery query = ActivitiesQuery
        .postsForGlobalFeed()
        .withFilter(ActivitiesQuery.Filter.NEWER, newestActivity.getId())
        .withLimit(15);

Filter By User

ActivitiesQuery class allows you to query activities posted by provided user. By default, it retrieves all activities.
For example, to get activities posted by current user:

1
2
3
4
String userId = GetSocial.User.getId();
ActivitiesQuery query = ActivitiesQuery
        .postsForGlobalFeed()
        .filterByUser(userId);

Friends Feed

You can ask to give you activities in feed, that were posted by you and your friends:

1
2
3
ActivitiesQuery query = ActivitiesQuery
        .postsForGlobalFeed()
        .friendsFeed(true);

Posts With Tags

You can filter all activities by tags, so you will have only activities that contain at least one tag from provided list:

1
2
3
ActivitiesQuery query = ActivitiesQuery
        .postsForGlobalFeed()
        .withTags("cat", "dog", "animal");

Open GetSocial Global Activity Feed View

GetSocialUI Library provides convenient way to show Activity Feed with all needed UI with a very little code execution:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
boolean wasShown = GetSocialUi.createGlobalActivityFeedView()
        .setButtonActionListener(new ActionButtonListener() {
            @Override
            public void onButtonClicked(String buttonAction, ActivityPost activityPost) {
                Log.i("GetSocial", "Button was pressed with action: " + buttonAction);
            }
        })
        .show();

Log.i("GetSocial", "GetSocial Activity Feed UI was shown: " + wasShown);

You will see the similar view on the screen:


GetSocial Activity Feed View

If you want to customize Activity Feed view, see UI Customization.

Also, read more about GetSocial UI.

Custom Activity Feed

Custom activity feed is automatically created by SDK, so you don’t need to check does it exist or create it manually. Just use it:

  1. To open GetSocial Activity Feed View:

    1
    GetSocialUi.createActivityFeedView("level-42").show();
    
  2. To create a query for custom feed activities:

    1
    ActivitiesQuery query = ActivitiesQuery.postsForFeed("level-42");
    

Feed name restrictions

Feed name could contain only alphanumeric symbols: letters [a-z], numbers [0-9], -, _, .; and should be not longer than 64 symbols.

User Avatar Click Listener

If you want to handle avatar click while using GetSocial UI, you can set AvatarClickListener when you’re creating view:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
```java
GetSocialUi.createGlobalActivityFeedView()
    .setAvatarClickListener(new AvatarClickListener() {
        @Override
        public void onAvatarClicked(PublicUser user) {
            handleAvatarClick(user);
        }
    })
    .show();
```

For example, on avatar click you could:

  • Open user profile;
  • Suggest to add a user to friends;
  • Show some in-game information for a user;
  • Send a message for a user, etc.

Listener is not invoked on application avatar click

AvatarClickListener is invoked only by click on the user avatar, not application one. Reach us via Intercom or support@getsocial.im if you need this functionality.

Activity Feed View For User

You can specify an user ID to show activity feed with only his posts.
For example, to show activity feed of current user:

1
2
3
4
String userId = GetSocial.User.getId();
GetSocialUi.createGlobalActivityFeedView()
    .setFilterByUser(userId)
    .show();

Friends Feed View

You can show Friends Activity Feed, that contains activities posted by you and your friends. To do that, simply set showFriendsFeed to true:

1
2
3
GetSocialUi.createGlobalActivityFeedView()
    .setShowFriendsFeed(true)
    .show();

Read-only Activity Feed View

If you want to hide controls, that allows user to post, comment, like or dislike activities, you can use Read-only feed feature:

1
2
3
4
boolean readOnlyFeed = true;
GetSocialUi.createGlobalActivityFeedView()
    .setReadOnly(readOnlyFeed)
    .show();

Also, you can restrict user from doing some actions with UiActionListener.

Activity Feed View Filtered By Tags

You can show Activity Feed with activities that contain at least one tag from provided list:

1
2
3
GetSocialUi.createGlobalActivityFeedView()
    .setFilterByTags("cat", "cats", "kitten")
    .show();

Give us your feedback! Was this article helpful?

😀 🙁