logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Manage users

ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of user management, allows users to update their personal profile, such as username, and status updates.

Implementation Process

Manage the extended field

The ZIM SDK provides user extended fields to describe additional properties of users. Developers can use extended fields to customize user attributes through the updateUserExtendedData interface. The usage of extended fields can be defined by developers, and the SDK will only pass the fields without any further processing.

After modifying the extended field properties, users can receive the modification results through ZIMUserExtendedDataUpdatedCallback.

Example
// Modify the user information extended field
String newUserExtendedData = "{\"user_avatar\":\"https://url\",\"user_name\":\"new_name\",\"user_sex\":\"male\",\"user_birth\":\"1970-01-01\",\"user_phone\":\"12345678901\"}";

zim.updateUserExtendedData(newUserExtendedData, new ZIMUserExtendedDataUpdatedCallback() {
        @Override
        public void onUserExtendedDataUpdated(String extendedData, ZIMError errorInfo) {
            if(errorInfo.code == ZIMErrorCode.SUCCESS) {
                // Modification succeeded
            }
        }
});
1
Copied!

Modify User Name

The user name userName is a string used to describe the user's nickname. Developers can configure it through the ZIMUserInfo object. The ZIM SDK supports users to modify their user names after logging in through the updateUserName interface.

After modifying the user name, users can receive the modification results through ZIMUserNameUpdatedCallback.

Example
// Modify the user name
// The userName is a string with a maximum length of 256 bytes, and there are no special character restrictions.
String newUserName = "new_name";
zim.updateUserName(newUserName, new ZIMUserNameUpdatedCallback() {
        @Override
        public void onUserNameUpdated(String userName, ZIMError errorInfo) {
            if(errorInfo.code == ZIMErrorCode.SUCCESS) {
                // Modification succeeded
            }
        }
});
1
Copied!

Set User Avatar

The ZIM SDK supports users to set or modify their avatars after logging in through the updateUserAvatarUrl interface.

After setting the user avatar, users can receive the setting results through the ZIMUserAvatarUrlUpdatedCallback.

Warning

When a user modifies his/her avatar, other users need to call the queryUsersInfo interface and set the isQueryFromServer parameter in ZIMUsersInfoQueryConfig to true to re-query the user information to obtain the latest avatar.

Example
// Set the user avatar
// The URL has a maximum length of 500 bytes, and there are no special character restrictions.
String userAvatarUrl = "xxx";
zim.updateUserAvatarUrl(userAvatarUrl, new ZIMUserAvatarUrlUpdatedCallback() {
    @Override
    public void onUserAvatarUrlUpdated(String userAvatarUrl, ZIMError errorInfo) {
        if(errorInfo.code == ZIMErrorCode.SUCCESS) {
            // Setting succeeded
        }
    }
});
1
Copied!

Query User Information

Users can query the full information of specified users, including user names and user extended fields, through the queryUsersInfo interface. Only in this interface can users obtain user avatar URLs and user extended field information.

After querying the information, users can receive the query results through the ZIMUsersInfoQueriedCallback.

Example
// Query user information

// Usage restrictions: The number of UserID to be queried in a single call to the interface cannot exceed 10; within 10 seconds, the cumulative total number of UserID queried by multiple calls to the interface cannot exceed 10.
ArrayList<String> userIDList = new ArrayList<>();
userIDList.add("user_id_1");

ZIMUsersInfoQueryConfig config = new ZIMUsersInfoQueryConfig();
config.isQueryFromServer = false;

zim.queryUsersInfo(userIDList, config, new ZIMUsersInfoQueriedCallback() {
        @Override
        public void onUsersInfoQueried(ArrayList<ZIMUserFullInfo> userList, ArrayList<ZIMErrorUserInfo> errorUserList, ZIMError errorInfo) {
            if(errorInfo.code == ZIMErrorCode.SUCCESS) {
                 // Query succeeded
            }
        }
});
1
Copied!

Previous

Authentication

Next

Multi-device login