/ UIKit / Android View
UIKit
Chat UIKit Android View v3
Chat UIKit Android View
Chat UIKit
Android View
Version 3

Add custom data to a message

Copy link

You can include additional data when sending a message through Sendbird UIKit. This page will guide you in two different ways to do so.


Set globally across the application

Copy link

This section shows how to add custom data in messages globally across the application. You can use the SendbirdUIKit.setCustomParamsHandler method to gather all events prior to the message being sent. The properties of each class that gets passed to the handler can be checked in this params reference. It's recommended to register the event handler in the onCreate() method of the Application. Global custom params, when declared, have a lower priority than those declared within a fragment.

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()
        SendbirdUIKit.setCustomParamsHandler(object : CustomParamsHandler {
            override fun onBeforeSendUserMessage(params: UserMessageCreateParams) {
                // Edit UserMessageCreateParams here.
            }
            override fun onBeforeSendFileMessage(params: FileMessageCreateParams) {
                // Edit FileMessageCreateParams here.
            }
            override fun onBeforeUpdateUserMessage(params: UserMessageUpdateParams) {
                // Edit UserMessageUpdateParams here.
            }
            override fun onBeforeSendMultipleFilesMessage(params: MultipleFilesMessageCreateParams) {
                // Edit MultipleFilesMessageCreateParams here.
            }
        })
    }
}

Set in a specific fragment

Copy link

This section shows how to add custom data to messages in a specific fragment. You can use custom parameters only for specific channels by inhering and implementing a Fragment. The custom implementations declared within a fragment have a higher priority than the global settings.

class MessageDataSampleFragment : ChannelFragment() {
    override fun onBeforeSendUserMessage(params: UserMessageCreateParams) {
        // Edit UserMessageCreateParams here.
    }
    override fun onBeforeSendFileMessage(params: FileMessageCreateParams) {
        // Edit FileMessageCreateParams here.
    }
    override fun onBeforeUpdateUserMessage(params: UserMessageUpdateParams) {
        // Edit UserMessageUpdateParams here.
    }
    override fun onBeforeSendMultipleFilesMessage(params: MultipleFilesMessageCreateParams) {
        // Edit MultipleFilesMessageCreateParams here.
    }
}

For an in-depth practical demonstration, see our sample code.