Chat UIKit Android View v2
Chat UIKit Android View
Chat UIKit
Android View
Version 2
Sendbird Chat UIKit v2 for Android View is no longer supported as a new version is released. Check out our latest Chat UIKit v3

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:

SendBirdUIKit.connect(new SendBird.ConnectHandler() {
    @Override
    public void onConnected(User user, SendBirdException 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.

SendBirdUIKit.disconnect(new SendBird.DisconnectHandler() {
    @Override
    public void onDisconnected() {
        // 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.

SendBirdUIKit.updateUserInfo(NICKNAME, PROFILE_URL, new SendBird.UserInfoUpdateHandler() {
    @Override
    public void onUpdated(SendBirdException e) {
        if (e != null) {
            // Handle error.
        }

        ...
    }
});