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.
}

Handle connection delays

Copy link

When the Sendbird server is experiencing high load, connection attempts may be delayed. UIKit provides built-in handling for this scenario through a countdown dialog that informs users about the delay and automatically retries the connection.

Connection delayed event

Copy link

You can observe connection delay events using the onConnectionDelayed live data in BaseViewModel. This allows you to implement custom handling for connection delays in your app.

KotlinJava
class MyChannelFragment : ChannelFragment() {
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        viewModel.onConnectionDelayed.observe(viewLifecycleOwner) { retryAfter ->
            // Handle connection delay. retryAfter is the delay in seconds.
            // By default, UIKit shows a countdown dialog.
        }
    }
}

Customize the connection delay dialog

Copy link

You can show or hide the default connection delay dialog using the showConnectionDelayedDialog() and hideConnectionDelayedDialog() methods in BaseModuleFragment. You can also use DialogUtils.showConnectionDelayedDialog() to display the default dialog with custom parameters.

KotlinJava
// Show default connection delay dialog
showConnectionDelayedDialog(retryAfter)

// Hide the dialog
hideConnectionDelayedDialog()

// Or use DialogUtils for custom implementation
DialogUtils.showConnectionDelayedDialog(context, retryAfter) {
    // Callback when dialog is dismissed
}

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.
})