Chat / Android
Chat Android v4
Chat Android
Chat
Android
Home
/
Chat
/
Android
/
User
This is the new Docs for Chat SDK v4 for Android. To see the previous Docs, click here.

Manage user metadata

Metadata consists of key-value items in which you can store additional information to users. You can add up to five key-value items for user metadata. Each key can have up to 128 characters and value can have up to 190 characters as String. This section explains how to manage user metadata.


Create metadata

You can create additional information such as phone number, email address or other descriptions to a user, which can be fetched or rendered into the UI. As an object, user metadata in Map<String, String> is stored into a User object.

To store user metadata into a User object, create Map<String, String> of key-value items, and then pass it as an argument to a parameter when calling the createMetaData() method. You can add multiple key-value items in the map.

val user = SendbirdChat.currentUser
val data = mapOf("key1" to "value1", "key2" to "value2")
user.createMetaData(data) { metaDataMap, e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

Retrieve

You can retrieve metadata stored to a user by calling the metaData property of a User object.

val user = SendbirdChat.currentUser
val metaData = user.metaData
val value = metaData["key"]

Update

You can update metadata of a user by adding map of key-value items, and then pass it as an argument to a parameter when calling the updateMetaData() method. Values of existing keys will be updated and values of new keys will be added. You can put multiple key-value items in the map.

val user = SendbirdChat.currentUser
val data = mapOf("key1" to "valueToUpdate1", "key2" to "valueToUpdate2")
user.updateMetaData(data) { metaDataMap, e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}

Delete

You can delete metadata stored to a user as below.

val user = SendbirdChat.currentUser
user.deleteMetaData("key1") { e ->
    if (e != null) {
        // Handle error.
    }

    // ...
}