Skip to main content
This page contains Android SDK code examples for Collaboration extensions. For feature documentation, setup instructions, and extension settings, see Collaboration Extensions.

How to Use Extensions with SDK

1

Enable in Dashboard

Login to CometChat Dashboard, select your app, then go to Chat & Messaging → Features and enable the extension.
2

Implement SDK methods

Use the code examples below to initiate collaboration sessions and extract URLs from messages.
3

Build your UI

Create UI components to display the collaboration interface (e.g., embed the whiteboard/document URL in a WebView).

Collaborative Document

Co-edit documents in real-time with other users.

Initiating the Session

val body = JSONObject()
body.put("receiverType", "user/group")
body.put("receiver", "uid/guid")

CometChat.callExtension("document", "POST", "/v1/create", body,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(responseObject: JSONObject) {
            // The document link to join as an initiator.
        }
        override fun onError(e: CometChatException) {
            // Some error occurred.
        }
    }
)

Extracting the URL from Received Message

val metadata = message.metadata
if (metadata != null) {
    val injectedObject = metadata.getJSONObject("@injected")
    if (injectedObject != null && injectedObject.has("extensions")) {
        val extensionsObject = injectedObject.getJSONObject("extensions")
        if (extensionsObject != null && extensionsObject.has("document")) {
            val documentExtension = extensionsObject.getJSONObject("document")
            val documentUrl = documentExtension.getString("document_url")
            // Use the document URL
        }
    }
}

Collaborative Whiteboard

Draw and brainstorm together on a shared whiteboard.

Initiating the Session

val body = JSONObject()
body.put("receiverType", "user/group")
body.put("receiver", "uid/guid")

CometChat.callExtension("whiteboard", "POST", "/v1/create", body,
    object : CometChat.CallbackListener<JSONObject>() {
        override fun onSuccess(responseObject: JSONObject) {
            // The whiteboard link to join as an initiator.
        }
        override fun onError(e: CometChatException) {
            // Some error occurred.
        }
    }
)

Extracting the URL from Received Message

val metadata = message.metadata
if (metadata != null) {
    val injectedObject = metadata.getJSONObject("@injected")
    if (injectedObject != null && injectedObject.has("extensions")) {
        val extensionsObject = injectedObject.getJSONObject("extensions")
        if (extensionsObject != null && extensionsObject.has("whiteboard")) {
            val whiteboardObject = extensionsObject.getJSONObject("whiteboard")
            val boardUrl = whiteboardObject.getString("board_url")
            // Use the whiteboard URL
        }
    }
}

Append Username to the Whiteboard URL

CometChat.getLoggedInUser(object : CometChat.CallbackListener<User>() {
    override fun onSuccess(user: User) {
        // Replace spaces with underscore
        val username = user.name.replace(" ", "_")
        // Append the username to the board_url
        val finalUrl = "$boardUrl&username=$username"
        // Use the final URL
    }

    override fun onError(e: CometChatException) {
        // Error getting user
    }
})