Stream Chat Client
is the official low-level Android SDK for Stream Chat, a service for building chat and messaging applications.
This library integrates directly with Stream Chat APIs and does not include UI; if you are interested in a SDK that includes UI components, you should check the stream-chat-android-core which comes with a collection of re-usable and customizable UI components.
dependencies {
implementation 'com.github.getstream:stream-chat-android-client:<latest-version>'
}
-
Create instance of client
val client = StreamChatClient("api-key", "token")
-
Set user
client.setUser(ChatUser("id), { result -> if(result.isSuccess()) getChannels() else showError(result.error()) }
-
Get channels
fun getChannels() { client.getChannels().enqueue { result -> if(result.isSuccess() showChannels(result.data()) else showError(result.error()) } }
-
Send message
client.sendMessage(channel, ChatMessage("hello"), { result -> //handle result }
-
Handle events
val subscription = client.events().subscribe { event -> if(event.type is ChatEvent.NEW_MESSAGE) showNewMessage(event.message) } subscription.unsubscribe()
All methods of the library return Call
object which allows to either execute
request immediatly in the same thread or enqueue
listener and get result in UI thread:
interface Call<T> {
fun execute(): Result<T>
fun enqueue(callback: (Result<T>) -> Unit)
fun cancel()
}
//sync
val result = client.getChannels().execute()
//async
client.getChannels { result -> showChannels(result) }
- Client life cycle
- Push messages
- Tokens
- SDK architecture