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

Delete a message

Copy link

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.

KotlinKTX
// 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

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

Group channel

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