/stream-chat-android

Official Android SDK for Stream Chat. Powerful client, offline support, and UI component libraries for awesome in-app chat features. Kotlin-first, Open-Source, free for Makers.

Primary LanguageKotlinOtherNOASSERTION

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

Java/Kotlin Chat Tutorial

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.

Free for Makers

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

Sample App

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.

Docs

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:

Supported features

  • 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

Installing the Kotlin/Java Chat SDK

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-ui-components:$stream_version"
}

Setup Stream Chat

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, this).offlineEnabled().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()
    }
}

Online status

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

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 via the ChatUI instance:

ChatUI.markdown = ChatMarkdown { textView, text ->
    // Do custom rendering here
    textView.text = text
}

Debug and development

Logging

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

We are hiring

We've recently closed a $38 million Series B funding round and we keep actively growing. Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world. Check out our current openings and apply via Stream's website.