Browse SDKs · Android
SDKsAndroid

Create a group

Use createGroup to create a group profile and specify its initial members, administrators, and owner.

Copy

Use createGroup() to create a group. Set the group profile in GroupInfo, and pass the initial regular members, administrators, and owner as separate parameters. The success callback returns the complete GroupInfo, including the new group's groupID.

Parameters

ParameterTypeRequiredDescription
memberUserIDsList<String>NoInitial regular members. Pass an empty list when none are needed.
adminUserIDsList<String>NoInitial administrators. Do not repeat a regular member or the owner.
infoGroupInfoYesGroup profile to create, including the fields required by your product.
ownerUserIDStringYesGroup owner. Do not also include this user as a member or administrator.
GroupInfo info = new GroupInfo();
info.setGroupName("Project discussion");
info.setIntroduction("For project members only");

OpenIMClient.getInstance().groupManager.createGroup(
    memberUserIDs, adminUserIDs, info, ownerUserID,
    new OnBase<GroupInfo>() {
        @Override public void onSuccess(GroupInfo group) { /* group contains the new group profile. */ }
        @Override public void onError(int code, String error) { /* code and error describe the failure. */ }
    }
);

Result

The success callback returns the created GroupInfo. Use its groupID to open the group chat, retrieve the profile, or continue managing members; do not persist a group identifier generated before the request.

A successful callback means this request completed, not that every client has already refreshed its joined-group list. Relevant users may subsequently receive onJoinedGroupAdded; merge that GroupInfo by groupID. See Group overview for the complete listener.