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.

Update a message

A user can update any of their own text and file messages sent using UserMessageUpdateParams and FileMessageUpdateParams. An error is returned if a user attempts to update another user's messages. In addition, channel operators can update any messages sent in a channel.

User message

val params = UserMessageUpdateParams().apply {
    message = NEW_TEXT_MESSAGE
    customType = NEW_CUSTOM_TYPE
    data = NEW_DATA
}

// The MESSAGE_ID argument below indicates the unique message ID of a UserMessage object to update.
channel.updateUserMessage(MESSAGE_ID, params) { message, e ->
    if (e != null) {
        // Handle error.
    }

    // The message is successfully updated.
    // Through the message parameter of the callback handler,
    // you can check if the update operation has been performed correctly.
}

File message

val params = FileMessageUpdateParams().apply {
    customType = NEW_CUSTOM_TYPE
}

// The MESSAGE_ID argument below indicates the unique message ID of a FileMessage object to update.
channel.updateFileMessage(MESSAGE_ID, params) { message, e ->
    if (e != null) {
        // Handle error.
    }

    // The message is successfully updated.
    // Through the message parameter of the callback handler,
    // you can check if the update operation has been performed correctly.
}

If a message is updated, the onMessageUpdated() method in the channel event handler will be invoked on all users' devices except the one that updated the message.

Open channel

SendbirdChat.addChannelHandler(
    UNIQUE_HANDLER_ID,
    object : OpenChannelHandler() {
        override fun onMessageUpdated(channel: BaseChannel, message: BaseMessage) {
            // ...
        }
        // ...
    }
)

Group channel

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