Skip to content

Stream Chat official Android SDK. The tutorial covers how to build your own chat experience using either Java or Kotlin.

License

Notifications You must be signed in to change notification settings

dmarin/stream-chat-android

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Official Android SDK for Stream Chat

Build status GitHub release

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.

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 [email protected]: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 to your repositories in your project level build.gradle file:

allprojects {
    repositories {
        mavenCentral()
    }
}

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"

    // for Java projects
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_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, 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()
    }
}

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 when you build your ChatUI instance:

val ui = ChatUI.Builder(context)
    .withMarkdown { textView, text ->
        // do custom rendering here
        textView.text = text
    }
    .build()

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

About

Stream Chat official Android SDK. The tutorial covers how to build your own chat experience using either Java or Kotlin.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 81.5%
  • Java 18.5%