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.

Delete a message

Users can delete any message they themselves have sent. An error is returned if a user attempts to delete messages sent by other users. Also channel operators can delete any messages in a channel.

// The BASE_MESSAGE argument below indicates a BaseMessage object to delete.
channel.deleteMessage(BASE_MESSAGE) { e ->
    if (e != null) {
        // Handle error.
    }

    // The message is successfully deleted from the channel.
}

After a message has been deleted, the onMessageDeleted() method in the channel event handler is invoked on all users' devices including the device where the message was deleted.

Open channel

SendbirdChat.addChannelHandler(
    UNIQUE_HANDLER_ID,
    object : OpenChannelHandler() {
        override fun onMessageDeleted(channel: BaseChannel, messageId: Long) {
            // ...
        }
        // ...
    }
)

Group channel

SendbirdChat.addChannelHandler(
    UNIQUE_HANDLER_ID,
    object : GroupChannelHandler() {
        override fun onMessageDeleted(channel: BaseChannel, messageId: Long) {
            // ...
        }
    }
)