> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-platform-docs-release.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Collaboration Extensions

> Android SDK implementation examples for Collaboration extensions including Collaborative Document and Collaborative Whiteboard

This page contains Android SDK code examples for Collaboration extensions. For feature documentation, setup instructions, and extension settings, see [Collaboration Extensions](/fundamentals/extensions-collaboration).

## How to Use Extensions with SDK

<Steps>
  <Step title="Enable in Dashboard">
    Login to [CometChat Dashboard](https://app.cometchat.com/login), select your app, then go to **Chat & Messaging → Features** and enable the extension.
  </Step>

  <Step title="Implement SDK methods">
    Use the code examples below to initiate collaboration sessions and extract URLs from messages.
  </Step>

  <Step title="Build your UI">
    Create UI components to display the collaboration interface (e.g., embed the whiteboard/document URL in a WebView).
  </Step>
</Steps>

***

## Collaborative Document

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

### Initiating the Session

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    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.
            }
        }
    )
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    JSONObject body = new JSONObject();
    body.put("receiverType", "user/group");
    body.put("receiver", "uid/guid");

    CometChat.callExtension("document", "POST", "/v1/create", body,
      new CometChat.CallbackListener<JSONObject>() {
        @Override
        public void onSuccess(JSONObject responseObject) {
            // The document link to join as an initiator.
        }
        @Override
        public void onError(CometChatException e) {
            // Some error occured.
        }
    });
    ```
  </Tab>
</Tabs>

### Extracting the URL from Received Message

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    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
            }
        }
    }
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    JSONObject metadata = message.getMetadata();
    if (metadata != null) {
        JSONObject injectedObject = metadata.getJSONObject("@injected");
        if (injectedObject != null && injectedObject.has("extensions")) {
            JSONObject extensionsObject = injectedObject.getJSONObject("extensions");
            if (extensionsObject != null && extensionsObject.has("document")) {
                JSONObject documentExtension = extensionsObject.getJSONObject("document");
                String documentUrl = documentExtension.getString("document_url");
                // Use the document URL
            }
        }
    }
    ```
  </Tab>
</Tabs>

***

## Collaborative Whiteboard

Draw and brainstorm together on a shared whiteboard.

### Initiating the Session

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    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.
            }
        }
    )
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    JSONObject body = new JSONObject();
    body.put("receiverType", "user/group");
    body.put("receiver", "uid/guid");

    CometChat.callExtension("whiteboard", "POST", "/v1/create", body,
      new CometChat.CallbackListener<JSONObject>() {
        @Override
        public void onSuccess(JSONObject responseObject) {
            // The whiteboard link to join as an initiator.
        }
        @Override
        public void onError(CometChatException e) {
            // Some error occured.
        }
    });
    ```
  </Tab>
</Tabs>

### Extracting the URL from Received Message

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    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
            }
        }
    }
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    JSONObject metadata = message.getMetadata();
    if (metadata != null) {
        JSONObject injectedObject = metadata.getJSONObject("@injected");
        if (injectedObject != null && injectedObject.has("extensions")) {
            JSONObject extensionsObject = injectedObject.getJSONObject("extensions");
            if (extensionsObject != null && extensionsObject.has("whiteboard")) {
                JSONObject whiteboardObject = extensionsObject.getJSONObject("whiteboard");
                String boardUrl = whiteboardObject.getString("board_url");
                // Use the whiteboard URL
            }
        }
    }
    ```
  </Tab>
</Tabs>

### Append Username to the Whiteboard URL

<Tabs>
  <Tab title="Kotlin">
    ```kotlin theme={null}
    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
        }
    })
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    CometChat.getLoggedInUser(new CometChat.CallbackListener<User>() {
        @Override
        public void onSuccess(User user) {
            // Replace spaces with underscore
            String username = user.getName().replace(" ", "_");
            // Append the username to the board_url
            String finalUrl = boardUrl + "&username=" + username;
            // Use the final URL
        }

        @Override
        public void onError(CometChatException e) {
            // Error getting user
        }
    });
    ```
  </Tab>
</Tabs>
