Skip to main content

Group management

This document guides developers on how to use RC's Android IMLib SDK to implement group creation, group profile settings, member removal, group exit, group dismissal, and group ownership transfer.

tip
  • This feature is supported starting from version 5.12.0
  • For groups created through the legacy group API /group/create.json, group hosting features are not available by default. You must call the Import Group Hosting Data API to set the group owner and default permissions first.

Enabling the Service

Before using this feature, you must enable the profile hosting service by submitting a ticket.

Group Event Listeners

Group events are defined in GroupEventListener, including group operations, group/member info changes, join requests, group remark synchronization, and special follow synchronization.
Call setGroupEventListener to set up group event listeners. Pass null to stop receiving group events.

tip

In User Profile Hosting service, SDK notifications for group operations count as status updates. The server will synchronize status with the SDK regardless of whether your app implements event listeners, ensuring local data remains current. These actions are included 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: create, join, remove, exit, dismiss, add/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 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 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 including:
// 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 sync callback for group remark changes
}

@Override
public void onGroupFollowsChangedSync(String groupId, GroupOperationType operationType, List<String> userIds, long operationTime) {
// Multi-device sync callback for special follow changes
}
};
RongCoreClient.getInstance().setGroupEventListener(groupEventListener);

Group Management

Includes: create group, set group profile, remove members, exit group, dismiss group, and transfer ownership.

Create Group

Call createGroup to create a new group.

API

RongCoreClient.getInstance().createGroup(groupInfo, inviteeUserIds, callback);

GroupInfo parameters:

ParameterTypeRequiredDescription
groupIdStringYesGroup ID: max 64 chars. Supports alphanumeric characters
groupNameStringYesGroup name: max 64 chars
portraitUriStringNoGroup avatar URL: max 128 chars
introductionStringNoGroup intro: max 512 chars
noticeStringNoGroup announcement: max 1024 chars
extProfileMap<String, String>NoCustom attributes: Add up to 10 key-value pairs for business needs. Must configure through Console Group Custom Attributes first
joinPermissionGroupJoinPermissionNoJoin permissions: no verification (default), owner verification, admin+owner verification, no joining allowed
removeMemberPermissionGroupOperationPermissionNoMember removal permissions: owner (default), owner+admins, all members
invitePermissionGroupOperationPermissionNoInvite permissions: owner (default), owner+admins, all members
inviteHandlePermissionGroupInviteHandlePermissionNoInvitation handling: no consent needed (default), require invitee consent
groupInfoEditPermissionGroupOperationPermissionNoProfile edit permissions: owner (default), owner+admins, all members. Only owner can modify this setting
memberInfoEditPermissionGroupMemberInfoEditPermissionNoMember profile edit permissions: self only, owner+self, owner+admins+self (default)

inviteeUserIds Parameter Introduction

You can optionally invite users to join the group during creation. A maximum of 30 users can be added at once.

The invitation outcome is affected by the group's invitee handling permission inviteHandlePermission parameter:

  • When invitee verification (InviteeVerify) is required, after successful group creation, the success callback's IRongCoreEnum.CoreErrorCode will return RC_GROUP_NEED_INVITEE_ACCEPT(25427). Invitees will receive the onGroupApplicationEvent event and must call the acceptGroupInvite interface to join.
  • When no invitee verification (Free) is required, after successful group creation, the success callback's IRongCoreEnum.CoreErrorCode will return SUCCESS(0), indicating invitees have joined the group.
tip
  • Group creation result isn't affected by IRongCoreEnum.CoreErrorCode - any onSuccess callback indicates successful creation.
  • Upon successful creation, the group owner receives an onGroupOperation callback with GroupOperation type Create.

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");
// Set user IDs to invite. 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 isn't empty, it indicates the specific GroupInfo key that caused the error
}
});

Update Group Information

Call updateGroupInfo to modify group name, announcement, permissions, and other details. Only groupId is required - other fields are optional, and only modified items will be updated.

tip
  • All members receive the onGroupInfoChanged callback upon successful update.
  • Group info update permission: groupInfoEditPermission. Only the group owner can modify this setting.

Sample Code

GroupInfo groupInfo = new GroupInfo();
// Group ID
groupInfo.setGroupId("groupId");
RongCoreClient.getInstance().updateGroupInfo(groupInfo, new IRongCoreCallback.OperationCallbackEx<String>() {
@Override
public void onSuccess() {
// Group info update succeeded
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e, String errorData) {
// Group info update failed. If errorData isn't empty, it indicates the specific GroupInfo key that caused the error
}
});

Remove Group Members

Call kickGroupMembers to remove users from the group.

This supports batch removal - you can pass multiple userIDs (up to 100) to remove multiple members at once.

The QuitGroupConfig setting controls whether to remove followed users, allowlist users, and muted members. By default, all are removed.

The removeMemberPermission (GroupOperationPermission) setting determines removal permissions. Calls without proper permissions return an error code.

tip
  • Upon successful removal, all members receive an onGroupOperation callback with GroupOperation type Kick.

Sample Code

// 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 removing followed users (default: YES)
config.setRemoveFollow(false);
// Disable removing allowlist (default: YES)
config.setRemoveWhiteList(false);
// Disable removing mute status (default: YES)
config.setRemoveMuteStatus(false);
RongCoreClient.getInstance().kickGroupMembers(groupId, userIds, config, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Removal succeeded
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Removal failed
}
});

Leave Group

Call quitGroup to leave a group voluntarily.

The QuitGroupConfig setting controls whether to remove followed users, allowlist users, and muted members. By default (when config isn't set), all are removed upon leaving.

tip
  • Upon successful exit, all members receive an onGroupOperation callback with GroupOperation type Quit.

Sample Code

// Group ID
String groupId = "groupId";
QuitGroupConfig config = new QuitGroupConfig();
// Disable removing followed users (default: YES)
config.setRemoveFollow(false);
// Disable removing allowlist (default: YES)
config.setRemoveWhiteList(false);
// Disable removing mute status (default: YES)
config.setRemoveMuteStatus(false);
RongCoreClient.getInstance().quitGroup(groupId, config, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Exit succeeded
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Exit failed
}
});

Dismiss Group

Call dismissGroup to disband a group.

After disbanding, group chat messages remain preserved, and local history isn't deleted.

tip
  • Only the group owner can disband the group.
  • Upon successful disbanding, all members receive an onGroupOperation callback with GroupOperation type Dismiss.

Sample Code

// Group ID
String groupId = "groupId";
RongCoreClient.getInstance().dismissGroup(groupId, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Disband succeeded
}

### Transfer group ownership

You can call the `transferGroupOwner` method to transfer group ownership to another user.

When calling `transferGroupOwner`, you can choose whether to quit the group after successful transfer (`quitGroup`). If set to `true`, you can also configure [QuitGroupConfig] options to control whether to remove followed users, allowlist users, and member mute status. If no config is set, all will be removed by default when quitting the group.

After successful transfer, all group members receive an [onGroupOperation] event with `GroupOperation` type `TransferGroupOwner`.

If you choose to quit the group during transfer, members will receive both the `TransferGroupOwner` event and a `Quit` event after successful transfer.

:::tip
- Only the group owner can transfer ownership.
:::

#### Sample Code
```java
// Group ID
String groupId = "groupId";
// New owner's user ID
String newOwnerId = "userId1";
// Quit group after transfer
boolean quitGroup = true;
QuitGroupConfig config = new QuitGroupConfig();
// Disable removing followed users (default: YES)
config.setRemoveFollow(false);
// Disable removing allowlist (default: YES)
config.setRemoveWhiteList(false);
// Disable removing member mute status (default: YES)
config.setRemoveMuteStatus(false);
RongCoreClient.getInstance().transferGroupOwner(groupId, newOwnerId, quitGroup, config, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Transfer succeeded
}

@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 group alias if set, otherwise showing the group name.
  • After setting or removing an alias, other devices will receive the multi-device sync callback onGroupRemarkChangedSync.

Set group alias

Call setGroupRemark to set a group alias.

To remove an alias, pass null or empty string "" as the remark parameter.

Sample Code

// Group ID
String groupId = "groupId";
// Group alias
String remark = "remark";
RongCoreClient.getInstance().setGroupRemark(groupId, remark, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {
// Set succeeded
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode coreErrorCode) {
// Set failed
}
});

Query group alias

Use getGroupsInfo to retrieve group information including the remark field.

Sample Code

// 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) {
// Retrieved group info successfully
if (groupInfos != null && !groupInfos.isEmpty()) {
for (GroupInfo info : groupInfos) {
String remark = info.getRemark();
// Retrieved group alias successfully
}
}
}

@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Retrieval failed
}
});