Skip to main content

Getting Started

The LikeMinds Android Feed SDK empowers you to integrate personalized and engaging feeds into your Android application, enhancing user experiences and driving user engagement. This guide will walk you through the steps to get started with the LikeMinds Android Feed SDK and set up a dynamic feed in your application. Obtain the necessary API key from the LikeMinds dashboard.

Prerequisites

Before you begin, ensure that you have the following:

  1. Kotlin Version: Your project's kotlin version should be greater than 1.6.0.
  2. Minimun Android SDK Version: minSdk should be atleast 21.
  3. Dependency Resolution Management: mavenCentral() and jitpack.io should be mentioned in dependencyResolutionManagement.

Step-by-Step Integration Guide

Follow these steps to integrate the LikeMinds Feed SDK into your Android application using MavenCentral:

Step 1 - Installation

Implement likeminds-feed-core project in your app level build.gradle.

dependencies {
...
implementation 'community.likeminds:likeminds-feed-core:1.3.2'
}
note

Set dataBinding true in your app level build.gradle if not done already.

Now, sync the gradle before moving to next step.

Step 2 - Setup LikeMinds Feed

Initiate LMFeedCore in onCreate() method of the Application class using the following code:

val application = this
val enablePushNotifications = false
val deviceId = null
val domain = "ENTER YOUR DOMAIN HERE"
val lmFeedCoreCallback = null

LMFeedCore.setup(
application = application,
enablePushNotifications = enablePushNotifications,
deviceId = deviceId,
domain = domain,
lmFeedCoreCallback = lmFeedCoreCallback
)
VARIABLETYPEDESCRIPTIONOPTIONAL
applicationApplicationInstance of your application class.
domainStringYour domain url.
enablePushNotificationsBooleanWhether to enable push notifications or not
deviceIdStringUnique Id of the device, if notifications are enabled
lmFeedThemeLMFeedSetThemeRequestRequest object to set theme to the Feed.
lmFeedCoreCallbackLMFeedCoreCallbackCallback for various operations in SDK .

Step 3 - Initiate User Session

You have successfully initiated the LMFeedCore. Now, you have to initiate a user session. You can initiate the user session using one of the following two approaches:

1. With API Key

This approach should be used when you want to manage LikeMinds authentication tokens on frontend. In this case you provide API Key directly to LikeMinds Feed SDK, which will be used to initiate a user session by calling LMFeedCore.showFeed().

val apiKey = "Your generated API key" // api key generated from the dashboard
val userName = "ENTER USER NAME" // name of the user
val userId = "ENTER USER ID" // id of the user
val context = this // instance of context

val successCallback = { response : UserResponse? ->
//user session initiated successfully, write your logic here
Unit
} // callback triggered when the initiate user call is successful

val failureCallback = { errorMessage ->
Log.e("Example", errorMessage)
Unit
} // callback triggered when the initiate user call fails

LMFeedCore.showFeed(
context = context,
apiKey = apiKey,
uuid = userId,
userName = userName,
success = successCallback,
error = failureCallback
)

2. Without API Key

This approach should be used when you want to manage LikeMinds authentication tokens on your backend server. In this case you eliminate the need to expose your API Key in your client app and your backend server is responsible for calling the Initiate API to obtain the accessToken and refreshToken which is passed to LMFeedCore.showFeed() to validate the user session.

  1. Create a function to get accessToken and refreshToken from your backend using Initiate API
suspend fun getTokens():Pair<String,String>{
// your implementation to fetch LikeMinds authentication tokens

return Pair(accessToken, refreshToken)
}
  1. While setting up LikeMinds Feed SDK in onCreate() method of the Application class, extend LMFeedCoreCallback and pass the instance of the same in LMFeedCore.setup()
val application = this
val enablePushNotifications = false
val deviceId = null
val domain = "ENTER YOUR DOMAIN HERE"

val lmFeedCoreCallback = object : LMFeedCoreCallback {
override fun onAccessTokenExpiredAndRefreshed(
accessToken: String,
refreshToken: String
) {
Log.d("Example","accessToken: $accessToken, refreshToken: $refreshToken")
}

override fun onRefreshTokenExpired(): Pair<String?, String?> {
return runBlocking{
getTokens()
}
}
}

LMFeedCore.setup(
application = application,
enablePushNotifications = enablePushNotifications,
deviceId = deviceId,
domain = domain,
lmFeedCoreCallback = lmFeedCoreCallback
)
info

LMFeedCoreCallback has two callbacks:

  1. onAccessTokenExpiredAndRefreshed(): This callback is triggered when the provided accessToken expires and is refreshed internally using the refreshToken.
  2. onRefreshTokenExpired() This callback is triggered when the provided refreshToken expires. In this case, you need to provide a new accessToken and refreshToken from your backend server using our initiate API.
  1. Upon receiving the accessToken and refreshToken from your backend server, call LMFeedCore.showFeed() function with these tokens.
val context = this // instance of context
val accessToken = "RECEIVED ACCESS TOKEN"
val refreshToken = "RECEIVED REFRESH TOKEN"

val successCallback = { response : UserResponse? ->
//user session initiated successfully, write your logic here
Unit
} // callback triggered when the initiate user call is successful

val failureCallback = { errorMessage ->
Log.e("Example", errorMessage)
Unit
} // callback triggered when the initiate user call fails

LMFeedCore.showFeed(
context = context,
accessToken = accessToken,
refreshToken = refreshToken,
success = successCallback,
error = failureCallback
)

Step 4 - Navigation to the feed

Once you have initiated the user session, you can navigate the user to your Feed in the above mentioned successCallback to be passed in LMFeedCore.showFeed(). LikeMinds provide various Feed Themes to which you can navigate with the help of following code:

// pass this successCallback to LMFeedCore.showFeed()
val successCallback = { response : UserResponse? ->
// inflate social feed fragment in your activity
val containerViewId = R.id.frame_layout
val fragment = LMFeedSocialFeedFragment()

val transaction = supportFragmentManager.beginTransaction()
transaction.replace(containerViewId, fragment, containerViewId.toString())
transaction.commit()
Unit
} // callback triggered when the initiate user call is successful
tip

By choosing the appropriate method based on your backend infrastructure and security preferences, you can seamlessly integrate the Feed SDK into your application while ensuring secure and efficient session management.

That's it! You have successfully integrated the LikeMinds Feed SDK into your Android application. The next step would be to explore additional customization options or configurations provided by the SDK to tailor the feed to your application's needs.