Skip to main content

User Profile

tip

IMKit supports two user profile display modes:

  • User Info Provider Delegate Pattern (current documentation): The app developer must actively fetch user profiles, group info, and group member profiles from the application server and provide them to the SDK. The nickname and avatar registered with the RC server during token acquisition are only used for push notifications.
  • User Profile Hosting: Starting from v5.12.0, IMKit supports switching to hosted user profiles for displaying user/group info in chat UIs and conversation lists.

IMKit uses the RongUserInfoManager class to centrally manage the following data. Apps must provide data to IMKit via RongUserInfoManager for UI display purposes.

  • User Profile: Includes nickname and avatar
  • Group Info: Includes group name and group avatar
  • Group Member Profiles: Only supports group member nicknames

This document focuses on how the application layer (App) provides nickname and avatar data (UserInfo) to IMKit SDK:

Refresh User Profile

If the app maintains local user profile data (e.g., the logged-in user's nickname and avatar), it can directly refresh the cached and database-stored user info (avatar and nickname). After refreshing, IMKit UI will automatically display the updated UserInfo.

User profile refreshes must occur after IMKit successfully establishes an IM connection; otherwise, local data cannot be updated. Typical use cases include:

  • After initial app launch and successful IM connection establishment, bulk-provide user profile data required by your business logic to the SDK. The SDK will write this data to cache and local database for future use.
  • If user profile changes (e.g., nickname/avatar updates) occur after IM connection, have the app server notify the client (e.g., via messages), then have the client call the refresh interface.
UserInfo userInfo = new UserInfo(userId, "Display name for userId", Uri.parse("Avatar URI for userId"));
RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo);

If the app doesn't maintain local data, we recommend dynamically providing user profiles when IMKit requires display data.

Dynamic User Profile Provision

Starting with IMKit v5.X, the SDK introduced the UserDataProvider.UserInfoProvider interface class. When IMKit cannot find user info in RongUserInfoManager, it triggers the getUserInfo callback method of UserInfoProvider. The app should provide required nicknames and avatars within this callback. After receiving the data, the SDK automatically updates and displays the user profile in relevant UIs.

Set User Info Provider to Supply Data to SDK

Call RongUserInfoManager's setUserInfoProvider method after app initialization but before establishing connection during the application lifecycle. If the SDK has previously obtained user info and persistent storage is enabled (isCacheGroupInfo=true), it caches the data in memory. The SDK prioritizes fetching user info from local databases, making the data available upon subsequent app launches. The SDK's default behavior when processing such data is:

  1. When displaying user info in UIs, IMKit first calls RongUserInfoManager's getUserInfo method per user ID to query cached or locally stored data.
  2. If found, the SDK immediately returns the data to the UI layer for display.
  3. If no local data exists, the SDK triggers UserDataProvider.UserInfoProvider's callback to attempt fetching from the application layer. Upon receiving the data, it refreshes the UI.
tip

We recommend setting isCacheGroupInfo=true to enable persistent group info storage.

Implement the getUserInfo callback in UserDataProvider.UserInfoProvider to supply user profile data to the SDK.

  • Asynchronous Fetch with Manual Refresh: Use this approach to avoid UI-blocking operations.

    1. Have getUserInfo return null while triggering your app's logic to asynchronously fetch the userId's profile data. Note: This temporarily sets the user's profile data to empty.

      RongUserInfoManager.getInstance().setUserInfoProvider(new UserDataProvider.UserInfoProvider {
      @Override
      public UserInfo getUserInfo(String userId) {
      ...// When displaying user info (e.g., in conversation list/chat UI), IMKit first calls getUserInfo per user ID.
      // Implement your async user info fetching logic here, then provide data to SDK via refreshUserInfoCache.
      return null;
      }

      }, true);
    2. After successfully obtaining the userId's profile data, manually refresh it by calling RongUserInfoManager's refreshUserInfoCache method. The SDK will update the UI upon receiving the data. See Refresh User Profile.

      UserInfo userInfo = new UserInfo(userId, "Display name for userId", Uri.parse("Avatar URI for userId"))
      RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo);
  • Synchronous Return: Alternatively, directly return the userId's profile data. The SDK will refresh the UI upon receipt.

    RongUserInfoManager.getInstance().setUserInfoProvider(new UserDataProvider.UserInfoProvider() {
    @Override
    public UserInfo getUserInfo(String userId) {
    UserInfo userInfo = new UserInfo(userId, "Display name for userId", Uri.parse("Avatar URI for userId"))
    return userInfo;
    }
    }, true);

Retrieve User Profile

Apps can actively call RongUserInfoManager's getUserInfo method to fetch cached user profiles. The SDK behavior is:

  1. First attempts to fetch app-provided data from local cache. If persistent storage was authorized during provider setup (isCacheUserInfo=true), the SDK also queries local databases.
  2. If no local data exists, triggers UserInfoProvider's getUserInfo callback. If your app implements this callback, the SDK can successfully retrieve UserInfo.
String userId = "User ID"
UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(userId)
ParameterTypeDescription
userIdStringUser ID