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.

Retrieve a list of users in an application

You can retrieve a list of all or certain users in your Sendbird application using an ApplicationUserListQuery instance. The next() method returns a list of User objects which contain information on users within the application.

// Retrieve all users.
val query = SendbirdChat.createApplicationUserListQuery(ApplicationUserListQueryParams())
query.next { users, e ->
    if (e != null) {
        // Handle error.
    }

    // A list of users is successfully retrieved.
    // Through the list parameter of the callback handler,
    // you can access the data of each user from the result list
    // that the Sendbird server has passed to the callback handler.
    // ...
}

ApplicationUserListQuery

The ApplicationUserListQueryParams object is passed to the createApplicationUserListQuery(:) method to make the ApplicationUserListQuery instance. Using a number of different parameters in the ApplicationUserListQuery instance, you can retrieve a list of specific users that match the set values in the parameters. Currently, the ApplicationUserListQuery instance supports the following parameters.

List of parameters

Parameter nameTypeDescription

userIdsFilter

string

Specifies the unique IDs of users you want to retrieve in the filter.

metaDataFilter

string

Specifies a metadata key to retrieve users with metadata containing an item with the specified key and values. The metaDataFilter property must be turned on to use the filter.

nicknameStartsWithFilter

string

Specifies the nickname of users you want to retrieve in the filter. This filter can be used with the nicknameStartsWithFilter property.

Note: We recommend you set the maximum number of user IDs to 250 in the UserID filter. If exceeded, your query may receive an HTTP 414 error indicating that the submitted request data is longer than the Sendbird server is willing to interpret.

// Retrieve certain users using the UserID filter.
val userIds = listOf("Harry", "Jay", "Jin")
val query = SendbirdChat.createApplicationUserListQuery(
    ApplicationUserListQueryParams().apply {
        userIdsFilter = userIds
    }
)
query.next { users, e ->
    if (e != null) {
        // Handle error.
    }

    // A list of matching users is successfully retrieved.
    // ...
}

// Retrieve certain users using the MetaDataKey filter.
val metaDataValues = listOf("movie", "book", "exercise")
val query = SendbirdChat.createApplicationUserListQuery(
    ApplicationUserListQueryParams().apply {
        metaDataFilter = "hobby" to metaDataValues
    }
)
query.next { users, e ->
    if (e != null) {
        // Handle error.
    }

    // A list of matching users is successfully retrieved.
    // ...
}