/ SDKs / Android
SDKs
Chat SDKs Android v4
Chat SDKs Android
Chat SDKs
Android
Version 4

Update a message

Copy link

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

Copy link
KotlinKTX
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

Copy link
KotlinKTX
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

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

Group channel

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