Skip to main content

User Profile Hosting

This document guides developers on implementing user profile subscription, querying, and monitoring in the RC Instant Messaging Android Client SDK, while supporting modification and querying of user profiles and permissions. Through this documentation, Android developers will learn how to obtain and track user profiles, as well as receive notifications when user profile changes or subscription status updates occur.

tip

This feature is supported starting from version 5.10.0.

Enabling the Service

The profile hosting service is enabled by default and can be used directly.

Managing User Profiles

You can modify or query your own user profile, or batch query profiles of multiple specified users.

Setting User Profiles

Users can modify their own profiles in the app using updateMyUserProfile. You need to configure relevant user profile information by creating an RCUserProfile object to set related attributes.

Interface

RongCoreClient.getInstance().updateMyUserProfile(userProfile, callback);

Parameter Description

The table below describes the attributes of the [UserProfile] class. Refer to the API documentation for details.

Attribute NameTypeDescription
nameStringNickname, with a maximum length of 32 characters.
portraitUriStringAvatar URL, with a maximum length of 128 characters.
uniqueIdStringUser application ID, supporting uppercase and lowercase letters and numbers, with a maximum length of 32 characters. Note: The SDK does not support setting this field.
emailStringEmail, with a maximum length of 128 characters.
birthdayStringBirthday, with a maximum length of 32 characters.
genderintGender: 0 for unknown, 1 for male, 2 for female.
locationStringLocation, with a maximum length of 32 characters.
roleintRole, supporting numbers between 0 and 100.
levelintLevel, supporting numbers between 0 and 100.
userExtProfilelongCustom extended information, allowing up to 20 user profile entries (set as Key-Value pairs. Extended user profiles are configured via the developer console).
  1. Key: Supports uppercase and lowercase letters and numbers, with a maximum length of 32 characters. Must be unique under the AppKey. Returns an error if the Key does not exist.
  2. Value: String, with a maximum length of 256 characters.

Example Code

// Update your own user profile
UserProfile userProfile = new UserProfile();
RongCoreClient.getInstance().updateMyUserProfile(userProfile, new IRongCoreCallback.UpdateUserProfileCallback() {
@Override
public void onSuccess() {
// Update successful
}

@Override
public void onError(int errorCode, String errorKey) {
// Update failed
}
});

Retrieving Current User Profile

You can use the getMyUserProfile method to retrieve the current user's profile.

Example Code

RongCoreClient.getInstance().getMyUserProfile(new IRongCoreCallback.ResultCallback<UserProfile>() {
@Override
public void onSuccess(UserProfile userProfile) {
// Query successful, returns your user profile.
}

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

Batch Retrieving User Profiles

You can use the getUserProfiles method to query profiles of specified users by passing their userIds.

tip
  • A maximum of 20 user profiles can be queried at once.

Example Code

// Set the list of user IDs to query
List<String> userIdList = new ArrayList<>();
userIdList.add("user1");
userIdList.add("user2");
userIdList.add("user3");
RongCoreClient.getInstance().getUserProfiles(userIdList, new IRongCoreCallback.ResultCallback<List<UserProfile>>() {
@Override
public void onSuccess(List<UserProfile> userProfiles) {
// Query successful, returns the queried user profiles.
}

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

Managing User Permissions

The RC IMLib SDK provides interfaces for setting and retrieving user-level permissions by configuring the UserProfileVisibility enum.

[UserProfileVisibility] Enum Description

Enum ValueUser Permission
UserProfileVisibility.NotSetNot Set: Follows the AppKey permission settings (default state).
UserProfileVisibility.InvisibleInvisible: No one can search for my user profile, except for name and avatar.
UserProfileVisibility.EveryoneEveryone: Any user in the app can view my user profile.
UserProfileVisibility.FriendVisibleFriends Only: Only users in my friend list can view my user profile.

User Permission Description

The default user profile access permission under an AppKey is Invisible, and the default user-level access permission is Not Set. When both are left unconfigured (i.e., both retain their default values), you can only view others' usernames and avatars.

Here is the comprehensive comparison between AppKey-level permissions and user-level permissions:

AppKey-level PermissionUser-level PermissionResult
Invisible, FriendVisible, or EveryoneNot SetFollows AppKey-level permission settings
Invisible, FriendVisible, or EveryoneSet (Invisible, FriendVisible, or Everyone)Follows user-level permission settings

Setting User Permissions

Use the updateMyUserProfileVisibility method to configure your own user profile access permissions.

Sample Code

// User profile permission setting
UserProfileVisibility visibility = UserProfileVisibility.Everyone;
RongCoreClient.getInstance().updateMyUserProfileVisibility(visibility, new IRongCoreCallback.ResultCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
// Successfully configured
}

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

Retrieving User Permissions

Use the getMyUserProfileVisibility method to obtain your current user profile access permissions.

Sample Code

// Retrieve own user permissions
RongCoreClient.getInstance().getMyUserProfileVisibility(new IRongCoreCallback.ResultCallback<UserProfileVisibility>() {
@Override
public void onSuccess(UserProfileVisibility userProfileVisibility) {
// Successfully retrieved
}

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

Exact Search by Application ID

Use the searchUserProfileByUniqueId method to search users by their application ID:

Sample Code

// Query user profile using application ID
String uniqueId = "uniqueId";
RongCoreClient.getInstance().searchUserProfileByUniqueId(uniqueId, new IRongCoreCallback.ResultCallback<UserProfile>() {
@Override
public void onSuccess(UserProfile userProfile) {
// Successful query
}

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

User Profile & Permission Change Subscriptions

Subscription Event Monitoring

To receive real-time notifications about subscription changes, you must configure the subscription listener after initializing the IMLib SDK but before establishing the connection.

Handle business logic based on the SubscribeType:

  • USER_PROFILE indicates user profile hosting
tip
  • Starting from v5.10.0, SubscribeType includes:
    • Online status subscription ONLINE_STATUS(1)
    • User profile hosting USER_PROFILE(2)
  • Starting from v5.12.0, new types were added:
    • Friend online status FRIEND_ONLINE_STATUS(3)
    • Friend user profile hosting FRIEND_USER_PROFILE(4)
RongCoreClient.getInstance().addSubscribeEventListener(new OnSubscribeEventListener() {
/**
* @param subscribeEvents List of changed subscription events.
* Note: When status changes occur for subscribed users, SubscribeEvent.operationType has no value.
* Subscription expiration doesn't trigger notifications - developers must track expiration independently.
* Key: Check SubscribeInfoEvent's SubscribeType - USER_PROFILE indicates user profile hosting.
*/
@Override
public void onEventChange(List<SubscribeInfoEvent> subscribeEvents) {

}

/**
* Marks completion of subscription data synchronization.
* Called after successful data sync to device/system for subsequent processing.
* Note: Check SubscribeType - USER_PROFILE indicates user profile hosting.
*
* @param type Synchronization completion type. Determine specific business logic by type.
* @since 5.10.0
*/
@Override
public void onSubscriptionSyncCompleted(SubscribeEvent.SubscribeType type) {

}

/**
* Triggered when subscription information changes on other devices.
* Ensures subscription consistency across devices.
* Note: Check SubscribeInfoEvent's SubscribeType - USER_PROFILE indicates user profile hosting.
* @param subscribeEvents List of subscription events
*/
@Override
public void onSubscriptionChangedOnOtherDevices(List<SubscribeEvent> subscribeEvents) {

}
});

Subscribing to Profile & Permission Changes

To track other users' profile and permission changes, use the subscribeEvent method:

  1. Create a SubscribeEventRequest object with:

    • Type: SubscribeEvent.SubscribeType.USER_PROFILE
    • User ID list (max 200 per request, total limit 1000 users)
    • Subscription duration (60-2,592,000 seconds)
  2. Note: You can be subscribed by max 5,000 users.

Sample Code

// Set subscription type
SubscribeEvent.SubscribeType type= SubscribeEvent.SubscribeType.USER_PROFILE;
// Set duration (seconds) between [60,2592000]
int expiry=180000;
// User IDs to subscribe (max 200 per request)
List<String> userList=new ArrayList<>();
userList.add("user1");
userList.add("user2");
userList.add("user3");
SubscribeEventRequest request = new SubscribeEventRequest(type,expiry,userList);
RongCoreClient.getInstance().subscribeEvent(request, new IRongCoreCallback.SubscribeEventCallback<List<String>>() {
@Override
public void onSuccess() {
// Subscription successful
}

@Override
public void onError(int errorCode, List<String> strings) {
// Subscription failed
}
});

Unsubscribing from Profile Changes

  1. Create a SubscribeEventRequest with:
    • Type: SubscribeEvent.SubscribeType.USER_PROFILE
    • User ID list (max 200 per request)

Sample Code

// Set unsubscribe type
SubscribeEvent.SubscribeType type= SubscribeEvent.SubscribeType.USER_PROFILE;
// User IDs to unsubscribe (max 200 per request)
List<String> userList=new ArrayList<>();
userList.add("user1");
userList.add("user2");
userList.add("user3");
SubscribeEventRequest request = new SubscribeEventRequest(type,userList);
RongCoreClient.getInstance().unSubscribeEvent(request, new IRongCoreCallback.SubscribeEventCallback<List<String>>() {
@Override
public void onSuccess() {
// Unsubscription successful
}

@Override
public void onError(int errorCode, List<String> strings) {
// Unsubscription failed
}
});

Querying Subscription Status for Specific Users

Use querySubscribeEvent to check subscription status for up to 200 users.

Sample Code

// Set query type
SubscribeEvent.SubscribeType type= SubscribeEvent.SubscribeType.USER_PROFILE;
// Query user online status
List<String> userList=new ArrayList<>();
userList.add("user1");
userList.add("user2");
userList.add("user3");
SubscribeEventRequest request = new SubscribeEventRequest(type,userList);
RongCoreClient.getInstance().querySubscribeEvent(request, new IRongCoreCallback.ResultCallback<List<SubscribeInfoEvent>>() {
@Override
public void onSuccess(List<SubscribeInfoEvent> subscribeInfoEvents) {
// Query successful, returns queried user information
}

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


### Paginated Query of Subscribed User Profile Hosting Status

If you need to paginate through all subscribed event status information, use the `querySubscribeEvent` method and specify the page size and starting index.


- Parameter pageSize: Page size [1~200]


- Parameter startIndex: Pass 0 for first page. For subsequent pages, pass the total count of returned data (e.g. if pageSize = 20, pass 20 for second page, 40 for third page)


#### Sample Code

```java
// Query type
SubscribeEvent.SubscribeType type= SubscribeEvent.SubscribeType.USER_PROFILE;
SubscribeEventRequest request = new SubscribeEventRequest(type);
// Page size, range [1,200]
int pageSize=20;
// Starting index - pass 0 for first page. For subsequent pages, pass the total count of returned data (e.g. if pageSize = 20, pass 20 for second page, 40 for third page)
int startIndex=0;
RongCoreClient.getInstance().querySubscribeEvent(request,pageSize,startIndex, new IRongCoreCallback.ResultCallback<List<SubscribeInfoEvent>>() {
@Override
public void onSuccess(List<SubscribeInfoEvent> subscribeInfoEvents) {
// Query successful, returns queried user information
}

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