Chat UIKit Android View v3
Chat UIKit Android View
Chat UIKit
Android View
Version 3

Authentication

Copy link

In order to use the features of Sendbird UIKit for Android in your client apps, a SendbirdUIKit instance must be initiated in each client app through user authentication with Sendbird server. The instance communicates and interacts with the server using an authenticated user account, and is allowed to use the UIKit's features. This page explains how to authenticate your user with the server.


Connect to Sendbird server

Copy link

Connect a user to Sendbird server using the SendbirdUIKit.connect() method with the information you provided in SendbirdUIKitAdapter. The connect() method also automatically updates the user profile on the server.

With local caching added to Sendbird Chat SDK, the latest user instance may be returned through the callback even when the user is offline. The local caching functionality stores message and channel data in the local storage and Sendbird server. As a result, even when a user is not connected to the server, the user information stored in the local cache is returned through the callback along with an error indicating the offline status.

Refer to the code below to see how to connect a user to Sendbird server:

KotlinJava
SendbirdUIKit.connect { user, e ->
    if (e != null) {
        if (user != null) {
            // The user is offline but you can access user information stored in the local cache.
        } else {
            // The user is offline and you can't access any user information stored in the local cache.
        }
    } else {
        // The user is online and connected to the server.
    }
}

Note: UIKit automatically establishes a connection when necessary. If a connection with Sendbird server is required before using a UIKit component, use the SendbirdUIKit.connect() method to establish a connection.


Disconnect from Sendbird server

Copy link

Call the SendbirdUIKit.disconnect() method if the user requests to log out. If a user has been logged out and thus disconnected from the server, they will no longer receive messages.

KotlinJava
SendbirdUIKit.disconnect {
    // The current user is disconnected from Sendbird server.
}

Update user profile

Copy link

Update a user's nickname or profile image using the SendbirdUIKit.updateUserInfo() method.

Note: Make sure to call this method after a connection has been established.

KotlinJava
val params = UserUpdateParams()
params.nickname = "NICKNAME"
params.profileImageUrl = "PROFILE_URL"
SendbirdUIKit.updateUserInfo(params, CompletionHandler { e ->
    if (e != null) {
        // Handle error.
        return@CompletionHandler
    }
    // do something.
})