ClickCease
Stories in Android apps

Quickly Implement Stories in Your Android App

Italo Orihuela
Italo Orihuela
Engineer
Android
Apr 3, 2024

In a time where attention spans are shorter than ever, stories have emerged as a compelling tool for user engagement. They offer a dynamic platform for users to share their experiences and moments in a concise yet captivating manner. This tutorial will guide you on how to implement Stories in your Android application using the Amity Social Cloud SDK.

We will delve into two types of stories: Image and Video, and discuss how to create them with optional StoryItems like HyperLink. We will also explore the different parameters required for story creation and how to handle various sync states. By the end of this tutorial, you will be equipped with the knowledge to enhance your app’s user experience with the addition of interactive stories.

Pre-requisites

  1. Basic knowledge of Android development.
  2. Familiarity with Kotlin programming language.
  3. The Amity Social Cloud SDK installed in your project.
  4. An Amity Social Cloud Portal account.
  5. An Amity Social Cloud Console Account.

Note: If you haven’t already registered for an Amity account, we recommend following our comprehensive step-by-step guide in the Amity Portal to create your new network.

Step 1: Understanding the Story Types

The Amity Social Cloud SDK offers two types of stories: Image and Video. An Image story allows the use of an image file of up to 1GB, while a Video story accommodates video files sized up to 2GB with a maximum duration of 90 seconds. The duration setting is adjustable at the network level, providing flexibility in configuration.

Step 2: Understanding StoryItems

Each story creation offers optional StoryItems. The first supported item type, HyperLink, enables inclusion of a URL and an alias, augmenting the story with additional content for user interaction. This feature allows seamless navigation to specified destinations upon story viewing. It’s important to note that the provided URL undergoes validation by the system against a predefined whitelist, configurable at the network level.

Step 3: Initiating Story Creation

To initiate story creation, the first step involves selecting the target type. Currently, the supported targetType is ‘community,’ necessitating the specification of a communityId for story creation within a specific community.

Step 4: Understanding Sync States

The Amity SDK utilizes optimistic story creation behavior, resulting in three possible sync states: ‘SYNCING,’ ‘SYNCED,’ and ‘FAILED.’ The sync state value is accessible as a property of the story model.

Step 5: Creating an Image Story and Video Story

The SDK provides the ‘createImageStory()’ and ‘createVideoStory()’ functions, allowing users to create a story with an image or video on the specified target. These functions require three parameters: targetType, targetId, and imageFile or videoFile. Additional parameters include storyItems, imageDisplayMode, and metadata.

Here’s a sample code snippet for creating an image story:

And here’s how you can create a video story:

Final Thoughts

Implementing Stories in your Android app can significantly enhance user engagement and provide a more interactive user experience. The Amity SDK simplifies this process, offering a suite of functions to craft stories and handle different sync states. By leveraging the Amity SDK, you can save significant cost and time in developing this feature, allowing you to focus on other aspects of your app. Take your Android app to the next level by integrating engaging stories.