Official Android SDK for Stream Chat
This is the official Android SDK for Stream Chat, a service for building chat and messaging applications. This library includes both a low-level chat SDK and a set of reusable UI components. Most users start with the UI components, and fall back to the lower level API when they want to customize things.
Quick Links for getting started
- Register to get an API key for Stream Chat
- Chat Tutorial (Kotlin)
- Chat Tutorial (Java)
- Documentation (Kotlin)
- Documentation (Java)
- API docs (Dokka)
- Sample app
- Wiki (Cookbooks/Docs)
The best place to start is the Android Chat Tutorial. It teaches you how to use this SDK and also shows you how to make frequently required changes. You can use either Java or Kotlin depending on your preference.
Stream is free for most side and hobby projects. To qualify your project/company needs to have < 5 team members and < $10k in monthly revenue. For complete pricing details visit our Chat Pricing Page
This repo includes a fully functional example app featuring threads, reactions, typing indicators, optimistic UI updates and offline storage. To run the sample app, start by cloning this repo:
git clone git@github.com:GetStream/stream-chat-android.git
Next, open Android Studio and open the newly created project folder. You'll want to run the stream-chat-android-ui-components-sample
app.
The
stream-chat-android-sample
module contains the sample app for our previous UI implementation.
The official documentation for the Chat SDK is available on our website. Each feature's page shows how to use it with the Android SDK, plus there are further Android-exclusive docs under the Android sections on the top.
The Chat Android SDKs support both Kotlin and Java usage, but we strongly recommend using Kotlin. The documentation is available in both languages.
You can also take a look at the full API documentation (generated by Dokka).
This SDK consists of the following modules / artifacts:
With these modules, the SDK provides:
- A low-level client for making API calls and receiving chat events
- Offline support and LiveData APIs module
- Ready to use ViewModels for displaying a list of channels and a conversation
- Reusable chat views:
- Channels list UI
- Channel UI
- Message reactions
- Link preview
- Image, video and file attachments
- Editing and deleting messages
- Typing indicators
- Read indicators
- Push notifications
- Image gallery
- GIF support
- Light and dark themes
- Style customization
- UI customization
- Threads
- Slash commands
- Markdown message formatting
- Count for unread messages
Step 1: Add MavenCentral and Jitpack to your repositories in your project level build.gradle
file:
allprojects {
repositories {
mavenCentral()
maven { url "https://jitpack.io" }
}
}
Step 2: Add the library as a dependency in your module level build.gradle
file:
See the releases page for the latest version number.
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
// for Kotlin projects
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "io.getstream:stream-chat-android:$stream_version"
}
Make sure to initialize the SDK only once; the best place to do this is in your Application
class.
class App : Application() {
override fun onCreate() {
super.onCreate()
val apiKey: String = ...
val user = User().apply {
id = ...
image = ...
name = ...
}
val client = ChatClient.Builder(apiKey, this).build()
val domain = ChatDomain.Builder(client, user, this).offlineEnabled().build()
val ui = ChatUI.Builder(this).build()
}
}
With this, you will be able to retrieve instances of the different components from any part of your application using instance()
. Here's an example:
class MainActivity: AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val chatClient = ChatClient.instance()
val chatDomain = ChatDomain.instance()
val chatUI = ChatUI.instance()
}
}
Connection status to Chat is available via ChatDomain.instance().online
which returns a LiveData object you can attach observers to.
ChatDomain.instance().online.observe(...)
Markdown support is based on Markwon 4. The SDK doesn't support all Markwon
features, support is limited to these plugins:
If you want to use a library other than Markwon or extend the Markwon plugins, you can use the code below to customize Markdown rendering when you build your ChatUI
instance:
val ui = ChatUI.Builder(context)
.withMarkdown { textView, text ->
// do custom rendering here
textView.text = text
}
.build()
By default, logging is disabled. You can enable logs and set a log level when initializing ChatClient
:
val client = ChatClient.Builder(apiKey, context)
.logLevel(ChatLogLevel.ALL)
.build()
If you need to intercept logs, you can also pass in your own ChatLoggerHandler
:
val client = ChatClient.Builder(apiKey, context)
.logLevel(ChatLogLevel.ALL)
.loggerHandler(object : ChatLoggerHandler {
override fun logD(tag: Any, message: String) {
// custom logging
}
...
})
.build()
To intercept socket errors:
client.subscribeFor<ErrorEvent> { errorEvent: ErrorEvent ->
println(errorEvent)
}
All SDK log tags have the Chat:
prefix, so you can filter for that those in the logs:
adb logcat com.your.package | grep "Chat:"
Here's a set of useful tags for debugging network communication:
Chat:Http
Chat:Events
Chat:SocketService