Group Management
This document guides developers on how to use RC's Android IMLib SDK to implement group management features including creating groups, setting group profiles, removing members, leaving groups, disbanding groups, and transferring group ownership.
-
This feature is supported starting from version 5.12.0.
-
For groups created via the legacy group interface
/group/create.json, group hosting related functions are not supported by default. You must call the Import Group Hosting Data interface to set the group owner (creator) and default permissions before using these features.
Service Activation
The information hosting service is enabled by default and can be used directly.
Group Event Listeners
Group events are defined in GroupEventListener, including group operations, group/member information changes, join requests, multi-device synchronization of group aliases, and multi-device synchronization of special follow lists.
You can set a group event listener using setGroupEventListener. Pass null to stop receiving group events.
In the information hosting service, SDK notification callbacks triggered by group operations are considered status notifications. Regardless of whether event listeners are implemented in the application, the server will synchronize status updates with the SDK to ensure local data remains current. These operations are counted in message distribution and downstream data statistics.
Code Example
GroupEventListener groupEventListener = new GroupEventListener() {
@Override
public void onGroupOperation(String groupId, GroupMemberInfo operatorInfo, GroupInfo groupInfo, GroupOperation operation, List<GroupMemberInfo> memberInfos, long operationTime) {
// Callback after group operations: including create/join/kick/leave/disband/add admin/remove admin/transfer ownership. See [GroupOperation]
}
@Deprecated
@Override
public void onGroupInfoChanged(GroupMemberInfo operatorInfo, GroupInfo groupInfo, List<GroupInfoKeys> updateKeys, long operationTime) {
// Group profile change callback. Note: Only attributes included in updateKeys are valid
}
/**
* Group profile change callback
*
* @param operatorInfo Operator's user info
* @param fullGroupInfo Complete group info
* @param changeGroupInfo Changed group info
* @param updateKeys List of changed attribute keys
* @param operationTime Operation timestamp
*/
default void onGroupInfoChanged(GroupMemberInfo operatorInfo,GroupInfo fullGroupInfo,GroupInfo changeGroupInfo,List<GroupInfoKeys> updateKeys,long operationTime) {
// Group profile change callback. Note: Only attributes included in updateKeys are valid
}
@Override
public void onGroupMemberInfoChanged(String groupId, GroupMemberInfo operatorInfo, GroupMemberInfo memberInfo, long operationTime) {
// Group member profile change callback
}
@Override
public void onGroupApplicationEvent(GroupApplicationInfo info) {
// Group application event callback. Includes:
// 1. User join requests or results
// 2. Invitation requests or results
}
@Override
public void onGroupRemarkChangedSync(String groupId, GroupOperationType operationType, String groupRemark, long operationTime) {
// Multi-device synchronization callback for group alias changes
}
@Override
public void onGroupFollowsChangedSync(String groupId, GroupOperationType operationType, List<String> userIds, long operationTime) {
// Multi-device callback for special follow list changes
}
};
RongCoreClient.getInstance().setGroupEventListener(groupEventListener);
Group Management
Group management includes: creating groups, setting group profiles, removing members, leaving groups, disbanding groups, and transferring ownership.
Creating Groups
Call createGroup to create a new group.
Interface
RongCoreClient.getInstance().createGroup(groupInfo, inviteeUserIds, callback);
GroupInfo Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| groupId | String | Yes | Group ID: Max 64 characters. Supports alphanumeric combinations (case-sensitive) |
| groupName | String | Yes | Group name: Max 64 characters |
| portraitUri | String | No | Group avatar URL: Max 128 characters |
| introduction | String | No | Group description: Max 512 characters |
| notice | String | No | Group announcement: Max 1024 characters |
| extProfile | Map<String, String> | No | Extended info: Custom attributes (Key/Value pairs) can be added based on business needs. Max 10 attributes. Custom attributes must be configured in RC Console [Group Custom Attributes] before use, otherwise settings will fail |
| joinPermission | GroupJoinPermission | No | Join permissions: No verification (default), Owner verification required, Owner+Admin verification required, No one allowed. Default used if not specified |
| removeMemberPermission | GroupOperationPermission | No | Member removal permissions: Owner (default), Owner+Admins, All members. Default used if not specified |
| invitePermission | GroupOperationPermission | No | Invitation permissions: Owner (default), Owner+Admins, All members. Default used if not specified |
| inviteHandlePermission | GroupInviteHandlePermission | No | Invitation handling: No invitee consent required (default), Invitee consent required. Default used if not specified |
| groupInfoEditPermission | GroupOperationPermission | No | Profile edit permissions: Owner (default), Owner+Admins, All members. Only owners can modify this permission. Default used if not specified |
| memberInfoEditPermission | GroupMemberInfoEditPermission | No | Member profile edit permissions: Self only, Owner+Self, Owner+Admins+Self (default). Default used if not specified |
inviteeUserIds Parameter
You can optionally invite users when creating a group. Maximum 30 users can be invited at once.
The invitation outcome depends on the group's invitation handling permission (inviteHandlePermission):
-
When invitee verification is required (
InviteeVerify), after successful group creation, the callbackIRongCoreEnum.CoreErrorCodewill returnRC_GROUP_NEED_INVITEE_ACCEPT(25427). Invitees receive the onGroupApplicationEvent and must callacceptGroupInviteto join. -
When no verification is required (
Free), after successful group creation, the callback returnsSUCCESS(0), indicating invitees have joined automatically.
-
The group creation result is not affected by
IRongCoreEnum.CoreErrorCode. As long as theonSuccesscallback is triggered, it indicates successful group creation. -
Upon successful group creation, the group owner will receive an onGroupOperation callback with
GroupOperationtypeCreate.
Sample Code
GroupInfo groupInfo = new GroupInfo();
// Group ID (Required, otherwise creation fails with error code)
groupInfo.setGroupId("groupId");
// Group name (Required, otherwise creation fails with error code)
groupInfo.setGroupName("groupName");
// List of invited user IDs (Optional)
List<String> inviteeUserIds = new ArrayList<>();
inviteeUserIds.add("userId1");
inviteeUserIds.add("userId2");
inviteeUserIds.add("userId3");
RongCoreClient.getInstance().createGroup(groupInfo, inviteeUserIds, new IRongCoreCallback.CreateGroupCallback() {
@Override
public void onSuccess(IRongCoreEnum.CoreErrorCode processCode) {
// Group creation request succeeded
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e, String errorData) {
// Group creation request failed. If errorData is not empty, it indicates the specific GroupInfo key that caused the error.
}
});
Updating Group Information
You can call the updateGroupInfo method to modify group details such as name, announcement, and permissions. Only the groupId field is required when updating group information - other fields will only be updated if modified.
-
After successful group information updates, all group members will receive an onGroupInfoChanged callback.
-
Update permissions are controlled by
groupInfoEditPermission, which can only be modified by the group owner.
Code Example
GroupInfo groupInfo = new GroupInfo();
// Group ID
groupInfo.setGroupId("groupId");
RongCoreClient.getInstance().updateGroupInfo(groupInfo, new IRongCoreCallback.OperationCallbackEx<String>() {
@Override
public void onSuccess() {
// Group information updated successfully
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e, String errorData) {
// Failed to update group information. If errorData is not empty, it indicates the specific GroupInfo key that caused the error.
}
});
Removing Group Members
You can call the kickGroupMembers method to remove users from a group.
This interface supports batch removal - you can remove up to 100 users at once by passing multiple userIDs.
The QuitGroupConfig parameter controls whether to remove followed users, allowlisted users, and muted members. If not set, all will be removed by default.
The removeMemberPermission (GroupOperationPermission) setting determines removal permissions. Calls without proper permissions will return an error code.
- After successful removal, all group members will receive an onGroupOperation callback with
GroupOperationtypeKick.
Code Example
// Group ID
String groupId = "groupId";
// User ID list
List<String> userIds = new ArrayList<>();
userIds.add("userId1");
userIds.add("userId2");
userIds.add("userId3");
QuitGroupConfig config = new QuitGroupConfig();
// Disable removal of followed users (default: YES)
config.setRemoveFollow(false);
// Disable removal from allowlist (default: YES)
config.setRemoveWhiteList(false);
// Disable removal of mute status (default: YES)
config.setRemoveMuteStatus(false);
RongCoreClient.getInstance().kickGroupMembers(groupId, userIds, config, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Removal successful
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Removal failed
}
});
Leaving a Group
You can call the quitGroup method to voluntarily leave a group.
The QuitGroupConfig parameter controls whether to remove followed users, allowlisted users, and muted members when leaving. If config is not set, all will be removed by default.
- After successfully leaving, all group members will receive an onGroupOperation callback with
GroupOperationtypeQuit.
Code Example
// Group ID
String groupId = "groupId";
QuitGroupConfig config = new QuitGroupConfig();
// Disable removal of followed users (default: YES)
config.setRemoveFollow(false);
// Disable removal from allowlist (default: YES)
config.setRemoveWhiteList(false);
// Disable removal of mute status (default: YES)
config.setRemoveMuteStatus(false);
RongCoreClient.getInstance().quitGroup(groupId, config, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Successfully left
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Failed to leave
}
});
Disbanding a Group
You can call the dismissGroup method to disband a group.
After successful disbanding, group chat messages remain preserved and local history messages are not deleted.
-
Only the group owner can disband a group.
-
After successful disbanding, all group members will receive an onGroupOperation callback with
GroupOperationtypeDismiss.
Code Example
// Group ID
String groupId = "groupId";
RongCoreClient.getInstance().dismissGroup(groupId, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Successfully disbanded
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Failed to disband
}
});
Transferring Group Ownership
You can call the transferGroupOwner method to transfer group ownership to another user.
When calling transferGroupOwner, you can choose whether to leave the group after successful transfer (quitGroup). If set to true, you can also configure QuitGroupConfig to control removal of followed users, allowlisted users, and muted members. If config is not set, all will be removed by default.
After successful transfer, all group members will receive an onGroupOperation callback with GroupOperation type TransferGroupOwner.
If leaving the group was selected during transfer, members will receive both TransferGroupOwner and Quit type callbacks.
- Only the group owner can transfer ownership.
Code Example
// Group ID
String groupId = "groupId";
// New owner's user ID
String newOwnerId = "userId1";
// Leave group after transfer
boolean quitGroup = true;
QuitGroupConfig config = new QuitGroupConfig();
// Disable removal of followed users (default: YES)
config.setRemoveFollow(false);
// Disable removal from allowlist (default: YES)
config.setRemoveWhiteList(false);
// Disable removal of mute status (default: YES)
config.setRemoveMuteStatus(false);
RongCoreClient.getInstance().transferGroupOwner(groupId, newOwnerId, quitGroup, config, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Transfer successful
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Transfer failed
}
});
Group Alias
Feature Description
-
Group aliases only take effect for the user who sets them. When new messages arrive while the user is offline, push notifications will display the alias if set, otherwise the group name.
-
After setting or removing an alias, other devices will receive the onGroupRemarkChangedSync callback for multi-device synchronization.
Setting Group Alias
You can call the setGroupRemark method to set a group alias.
To remove a group alias, pass null or an empty string "" as the remark parameter.
Code Example
// Group ID
String groupId = "groupId";
// Group alias
String remark = "remark";
RongCoreClient.getInstance().setGroupRemark(groupId, remark, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Successfully set
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
// Failed to set
}
});
### Querying Group Alias
You can use the `getGroupsInfo` method to retrieve group information, which includes the `remark` field.
#### Code Example
```java
// List of group IDs
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
if (groupInfos != null && !groupInfos.isEmpty()) {
for (GroupInfo info : groupInfos) {
String remark = info.getRemark();
// Successfully obtained the group's remark
}
}
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Failed to retrieve
}
});