Live Android v1
Live Android
Live
Android
Home
/
Live
/
Android
/
SDK

Manage custom items

With custom items for live events, you can store additional information as key-value pairs to the LiveEvent object. Custom key-value items are saved as a <String, String> dictionary and can be updated or deleted by the users specified in userIdsForHost. Information related to the live event can be added as custom items for better user experience.


Add

When creating a live event, users can add custom items by adding it to LiveEventParams as <String, String> dictionary type. By default, customItems is an empty dictionary.

val map: Map<String, String> = mapOf("key1" to "value1", "key2" to "value2", "key3" to "value3")
val params = LiveEventParams(listOf("HOST_ID")).apply {
   title = "TITLE"
   coverImage = "IMAGE_URL"
   customItems = map
}
SendbirdLive.createLiveEvent(params){ liveEvent, e ->
   if (e != null){
       return@createLiveEvent
   }
   // A live event is successfully created with custom items.

}

Update and delete

Custom items can be updated or deleted when a live event is in the ongoing state. If a new custom item has the same key as the existing custom item, the new item will update the value of the existing item. A new item with a new key will be added to the list of custom items. You can update existing custom items by calling liveEvent.updateCustomItems().

You can delete custom items by calling liveEvent.deleteCustomItems() with the list of keys that you want to delete from the list of custom items. If you want to delete all custom items in a live event, you can call liveEvent.deleteAllCustomItems().

// update custom items
val map: Map<String, String> = mapOf("key1" to "value1", "key2" to "value2", "key3" to "value3")
liveEvent.updateCustomItems(customItems) { customItems, affectedKeys, e ->
    if (e != null) {
        return@updateCustomItems
    }

}

// delete custom items
val list: List<String> = listOf("key1", "Key2")
liveEvent.deleteCustomItems(list) { customItems, affectedKeys, e ->
    if (e != null) {
        return@deleteCustomItems
    }
}

Receive events

A participant in a live event can receive events from the Sendbird server when the custom items is modified. The events are delivered to LiveEventListener only when the live event is in the ongoing state. Implement onCustomItemsUpdate(updatedKeys:) and onCustomItemsDelete(deletedKeys:) from LiveEventListener to receive events in the live event. Each event contains the list of keys of the changed custom items, such as updatedKeys or deletedKeys.

val listener: LiveEventListener = object : LiveEventListener {
    ...

    override fun onCustomItemsDelete(liveEvent: LiveEvent, customItems: Map<String, String>, deletedKeys: List<String>) {
        Log.v("[SendbirdLiveUIKit]", "onCustomItemsDelete deletedKeys: ${deletedKeys.joinToString(", ")}")
    }

    override fun onCustomItemsUpdate(liveEvent: LiveEvent, customItems: Map<String, String>, updatedKeys: List<String>) {
        Log.v("[SendbirdLiveUIKit]", "onCustomItemsUpdate updatedKeys: ${updatedKeys.joinToString(", ")}")
    }
}