Chat / Android
Chat Android v4
Chat Android
Chat
Android
Home
/
Chat
/
Android
/
Message
This is the new Docs for Chat SDK v4 for Android. To see the previous Docs, click here.

Receive messages in a group channel

Messages sent from other members can be received through the onMessageReceived() method in a channel event handler. A BaseMessage object for each received message is one of the following three message types.

Message typeDescription

UserMessage

A text message sent by a user

FileMessage

A binary file message sent by a user

AdminMessage

A text message sent by an admin through the Chat API

To register multiple concurrent handlers, pass a UNIQUE_HANDLER_ID argument as a unique identifier into the SendbirdChat.addChannelHandler() method.

SendbirdChat.addChannelHandler(
    UNIQUE_HANDLER_ID,
    object : GroupChannelHandler() {
        override fun onMessageReceived(channel: BaseChannel, message: BaseMessage) {
            when (message) {
                is UserMessage -> {
                    // ...
                }
                is FileMessage -> {
                    // ...
                }
                is AdminMessage -> {
                    // ...
                }
            }
        }
    }
)

When the UI isn't valid anymore, remove the channel event handler.

SendbirdChat.removeChannelHandler(UNIQUE_HANDLER_ID);

Event handler for message threading

When a reply is created in a channel, the onMessageReceived() method of the channel event handler in client apps is called. Once a reply is created or deleted from a thread, the onThreadInfoUpdated() event handler is invoked. The method returns a ThreadInfoUpdateEvent object that has the latest information about the thread. This object needs to be applied to the parent message object.

override fun onThreadInfoUpdated(channel: BaseChannel, threadInfoUpdateEvent: ThreadInfoUpdateEvent) {
    // Look for a message that has threadInfoUpdateEvent.targetMessageId.
    // Apply the event to the message.
    parentMessage.applyThreadInfoUpdateEvent(threadInfoUpdateEvent)
}

List of parameters

Parameter nameTypeDescription

channel

BaseChannel

Specifies the channel that has the message thread.

threadInfoUpdateEvent

ThreadInfoUpdateEvent

Specifies a ThreadInfoUpdateEvent object that has the latest information about the thread.


Receive callbacks for delivery receipts

When a message is delivered to group channel members who are online, it is automatically marked as delivered and channel members are also notified of the successful message delivery through the onDeliveryStatusUpdated() method in the channel event handler.

SendbirdChat.addChannelHandler(
    UNIQUE_HANDLER_ID,
    object : GroupChannelHandler() {
        override fun onMessageReceived(channel: BaseChannel, message: BaseMessage) {}

        override fun onDeliveryStatusUpdated(channel: GroupChannel) {
            // ...
        }
    }
)