Group Query
This document guides developers on how to use RC IMLib SDK to implement features like retrieving joined groups and obtaining specific group information.
Enabling the Service
Before using this feature, you must enable the profile hosting service by submitting a ticket.
Group Query
Query or search groups you've joined.
Get Group Information
Call the getGroupsInfo
method to retrieve group information.
- This method prioritizes local lookup. When the user isn't in the group, or if local group information doesn't exist or has been cached for over 10 minutes, it fetches the latest group data from the server.
- A single call supports retrieving information for up to 20 groups.
Code Example
// Group ID list
List<String> groupIds = new ArrayList<>();
groupIds.add("groupId1");
groupIds.add("groupId2");
groupIds.add("groupId3");
RongCoreClient.getInstance().getGroupsInfo(groupIds, new IRongCoreCallback.ResultCallback<List<GroupInfo>>() {
@Override
public void onSuccess(List<GroupInfo> groupInfos) {
// Successfully retrieved group information
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Failed to retrieve group information
}
});
Get Information for Specified Joined Groups
Use getJoinedGroups
to retrieve group information based on the current user's joined group IDs.
This interface supports batch retrieval—you can pass multiple groupId
parameters to get information for up to 20 groups at once.
Code Example
// Group ID list
List<String> groupIds = new ArrayList<>();
groupIds.add("groupId1");
groupIds.add("groupId2");
groupIds.add("groupId3");
RongCoreClient.getInstance().getJoinedGroups(groupIds, new IRongCoreCallback.ResultCallback<List<GroupInfo>>() {
@Override
public void onSuccess(List<GroupInfo> groupInfos) {
// Retrieval successful
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Retrieval failed
}
});
Get Joined Groups by Role
Use getJoinedGroupsByRole
to paginate through joined groups based on member roles.
This interface supports returning the total count matching query conditions—see getTotalCount()
in [PagingQueryOption].
Parameter Description
GroupMemberRole
enum values:
Enum Value | Group Member Role |
---|---|
Undef | Undefined role (queries all member types) |
Normal | Regular group member |
Manager | Administrator |
Owner | Group Owner |
Pagination notes:
- For initial retrieval, leave
pageToken
in [PagingQueryOption] unset (equivalent to setting null or ""). - For subsequent pages, use the
pageToken
returned in [PagingQueryResult].- If not "", pass this value to retrieve the next page until "" indicates completion.
- If "", no more pages exist. Passing "" will retrieve the first page.
Example Code
{
//...
String pageToken = "";
getJoinedGroupsByRole(pageToken);
//...
}
public void getJoinedGroupsByRole(String pageToken) {
// Query groups for all member roles
GroupMemberRole role = GroupMemberRole.Undef;
// Pagination parameters
PagingQueryOption option = new PagingQueryOption();
// Page size (1-100)
option.setCount(20);
// Pagination token
option.setPageToken(pageToken);
// Sort by join time: true=ascending, false=descending
option.setOrder(false);
RongCoreClient.getInstance().getJoinedGroupsByRole(role, option, new IRongCoreCallback.PageResultCallback<GroupInfo>() {
@Override
public void onSuccess(PagingQueryResult<GroupInfo> result) {
if (!TextUtils.isEmpty(result.getPageToken())) {
// Use returned pageToken for next page
getJoinedGroupsByRole(result.getPageToken());
} else {
// Retrieval complete
}
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Retrieval failed
}
});
}
Search Joined Groups by Name
Use searchJoinedGroups
to search joined groups by name.
This interface supports returning the total count matching query conditions—see getTotalCount()
in PagingQueryOption
.
Pagination notes:
- For initial retrieval, leave
pageToken
inPagingQueryOption
unset (equivalent to setting null or ""). - For subsequent pages, use the
pageToken
returned inPagingQueryResult
.- If not "", pass this value to retrieve the next page until "" indicates completion.
- If "", no more pages exist. Passing "" will retrieve the first page.
Code Example
{
//...
// Pagination token (null and "" are equivalent)
String pageToken = "";
searchJoinedGroups(pageToken);
//...
}
public void searchJoinedGroups(String pageToken) {
// Group name
String groupName = "groupName";
// Pagination parameters
PagingQueryOption option = new PagingQueryOption();
// Page size (1-200)
option.setCount(20);
// Pagination token
option.setPageToken(pageToken);
// Sort by join time: true=ascending, false=descending
option.setOrder(false);
RongCoreClient.getInstance().searchJoinedGroups(groupName, option, new IRongCoreCallback.PageResultCallback<GroupInfo>() {
@Override
public void onSuccess(PagingQueryResult<GroupInfo> result) {
if (!TextUtils.isEmpty(result.getPageToken())) {
// Use returned pageToken for next page
searchJoinedGroups(result.getPageToken());
} else {
// Retrieval complete
}
}
<!-- links -->
[getJoinedGroups]:https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/en_US/html/-android--i-m-lib-core--s-d-k/io.rong.imlib/-rong-core-client/get-joined-groups.html
[getJoinedGroupsByRole]:https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/en_US/html/-android--i-m-lib-core--s-d-k/io.rong.imlib/-rong-core-client/get-joined-groups-by-role.html
[getGroupsInfo]:https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/en_US/html/-android--i-m-lib-core--s-d-k/io.rong.imlib/-rong-core-client/get-groups-info.html
[PagingQueryOption]: https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/en_US/html/-android--i-m-lib-core--s-d-k/io.rong.imlib.model/-paging-query-option/index.html
[PagingQueryResult]: https://doc.rongcloud.cn/apidoc/imlibcore-android/latest/en_US/html/-android--i-m-lib-core--s-d-k/io.rong.imlib.model/-paging-query-result/index.html