User Profile Hosting
This document guides developers on implementing user profile subscription, querying, and monitoring in the RC Instant Messaging Android SDK, while supporting modifications and queries of user profiles and permissions.
Through this documentation, you will learn how to obtain and track user profiles, as well as receive notifications when user profiles or subscription statuses change.
This feature is supported starting from version 5.10.0.
Enabling the Service
Before using this feature, you must enable the profile hosting service by submitting a ticket.
Managing User Profiles
You can modify or query your own user profile, or batch query profiles for multiple specified users.
Setting User Profiles
Users can modify their own profiles using updateMyUserProfile
within the app. Configure relevant profile information by creating an RCUserProfile
object to set properties.
Interface
RongCoreClient.getInstance().updateMyUserProfile(userProfile, callback);
Parameter Description
The table below describes attributes of the UserProfile
class.
Attribute | Type | Description |
---|---|---|
name | String | Nickname (max 32 characters) |
portraitUri | String | Avatar URL (max 128 characters) |
uniqueId | String | User application ID (supports alphanumeric characters, max 32 chars). Note: SDK doesn't support setting this field. |
String | Email (max 128 characters) | |
birthday | String | Birthday (max 32 characters) |
gender | int | Gender (0: unknown, 1: male, 2: female) |
location | String | Location (max 32 characters) |
role | int | Role (supports values 0-100) |
level | int | Level (supports values 0-100) |
userExtProfile | long | Custom extension info (max 20 key-value pairs)
|
Example Code
// Update 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
Use getMyUserProfile
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 own user profile
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Query failed
}
});
Batch Retrieving User Profiles
Use getUserProfiles
to query profiles for specified users by passing their userIds.
- Maximum 20 user profiles per query.
Sample Code
// Set 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 requested 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 through the UserProfileVisibility
enum.
UserProfileVisibility
Enum Description
Enum Value | Permission |
---|---|
UserProfileVisibility.NotSet | Not set: Follows AppKey-level permissions (default state) |
UserProfileVisibility.Invisible | Invisible: No one can search my profile (except name and avatar) |
UserProfileVisibility.Everyone | Everyone: All users can view my profile |
UserProfileVisibility.FriendVisible | Friends only: Only users in my friend list can view my profile |
Permission Notes
The default AppKey-level profile access permission is Invisible, while the default user-level permission is Not set. When both remain at default values, you can only view others' usernames and avatars.
Combined permission behavior:
AppKey-Level Permission | User-Level Permission | Result |
---|---|---|
Invisible/Friends only/Everyone | Not set | Follows AppKey-level permission |
Invisible/Friends only/Everyone | Set value (Invisible/Friends only/Everyone) | Follows user-level permission |
Setting User Permissions
Use updateMyUserProfileVisibility
to set your own profile access permissions.
Sample Code
// Set profile visibility
UserProfileVisibility visibility = UserProfileVisibility.Everyone;
RongCoreClient.getInstance().updateMyUserProfileVisibility(visibility, new IRongCoreCallback.ResultCallback<Boolean>() {
@Override
public void onSuccess(Boolean result) {
// Update successful
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Update failed
}
});
Retrieving User Permissions
Use getMyUserProfileVisibility
to get your current profile access permissions.
Sample Code
// Get my permission settings
RongCoreClient.getInstance().getMyUserProfileVisibility(new IRongCoreCallback.ResultCallback<UserProfileVisibility>() {
@Override
public void onSuccess(UserProfileVisibility userProfileVisibility) {
// Retrieval successful
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Retrieval failed
}
});
User Search
Exact Search by Unique ID
Use searchUserProfileByUniqueId
to search users by their unique application ID:
Sample Code
// Search user by unique ID
String uniqueId = "uniqueId";
RongCoreClient.getInstance().searchUserProfileByUniqueId(uniqueId, new IRongCoreCallback.ResultCallback<UserProfile>() {
@Override
public void onSuccess(UserProfile userProfile) {
// Search successful
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Search failed
}
});
User Profile & Permission Subscription
Subscription Event Listening
To receive subscription event notifications, set up the subscription listener after initializing the IMLib SDK but before establishing the connection.
Handle business logic based on the SubscribeType
- when equal to USER_PROFILE
, it indicates user profile hosting.
- Starting from v5.10.0,
SubscribeType
includes online status subscriptionONLINE_STATUS(1)
and user profile hostingUSER_PROFILE(2)
- Starting from v5.12.0,
SubscribeType
adds friend online statusFRIEND_ONLINE_STATUS(3)
and friend profile hostingFRIEND_USER_PROFILE(4)
RongCoreClient.getInstance().addSubscribeEventListener(new OnSubscribeEventListener() {
/**
* @param subscribeEvents List of subscription events containing all changes
* When subscribed targets change status, SubscribeEvent.operationType has no value
* Subscription expiration doesn't trigger notifications - developers must track expiration manually
* Note: 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 subscription data successfully syncs to device/system
* Note: Check SubscribeType - USER_PROFILE indicates user profile hosting
*
* @param type Sync completion type - determine specific business completion by type
* @since 5.10.0
*/
@Override
public void onSubscriptionSyncCompleted(SubscribeEvent.SubscribeType type) {
}
/**
* Called when subscription info changes on other devices
* Used to update local user status and maintain consistency
* Note: Check SubscribeInfoEvent's SubscribeType - USER_PROFILE indicates user profile hosting
* @param subscribeEvents List of subscription events
s SubscribeType - USER_PROFILE indicates user profile hosting
* @param subscribeEvents List of subscription events
*/
@Override
public void onSubscriptionChangedOnOtherDevices(List<SubscribeEvent> subscribeEvents) {
}
});
Subscribing to User Profile & Permission Changes
To track changes in other users' profile information and permissions, use the subscribeEvent
method to subscribe to user profile change events.
-
Create a
SubscribeEventRequest
object, set the subscription type toSubscribeEvent.SubscribeType.USER_PROFILE
, specify the user IDs to subscribe to, and set the subscription duration. Note: You can subscribe to up to 200 users at once, with a maximum of 1000 subscribed users total. Each user can be subscribed by up to 5000 others. -
Set subscription duration: Define an integer value representing the subscription period in seconds (range: 60 to 2592000 seconds).
Example Code
// Set subscription type
SubscribeEvent.SubscribeType type= SubscribeEvent.SubscribeType.USER_PROFILE;
// Set subscription duration in seconds (range: 60-2592000)
int expiry=180000;
// User IDs to subscribe to (targetId for one-to-one chat, 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 User Profile & Permission Changes
- When you no longer need to track changes for subscribed users, create a
SubscribeEventRequest
object with typeSubscribeEvent.SubscribeType.USER_PROFILE
and specify the user IDs to unsubscribe (max 200 per request).
Example Code
// Set unsubscribe type
SubscribeEvent.SubscribeType type= SubscribeEvent.SubscribeType.USER_PROFILE;
// User IDs to unsubscribe (targetId for one-to-one chat, 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 specified users and subscription types (max 200 users per query).
Example Code
// Set query type
SubscribeEvent.SubscribeType type= SubscribeEvent.SubscribeType.USER_PROFILE;
// User IDs to query
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 user profile information
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Query failed
}
});
Paginated Query for Subscribed User Profile Status
For paginated retrieval of all subscribed event statuses, use querySubscribeEvent
with specified page size and start index.
- Parameter pageSize: Page size [1~200]
- Parameter startIndex: Pass 0 for first page. For subsequent pages, pass the cumulative count of returned data (e.g., if pageSize=20, pass 20 for page 2, 40 for page 3)
Example Code
// Query type
SubscribeEvent.SubscribeType type= SubscribeEvent.SubscribeType.USER_PROFILE;
SubscribeEventRequest request = new SubscribeEventRequest(type);
// Page size (range: 1-200)
int pageSize=20;
// Start index (0 for first page, cumulative count for subsequent pages)
int startIndex=0;
RongCoreClient.getInstance().querySubscribeEvent(request,pageSize,startIndex, new IRongCoreCallback.ResultCallback<List<SubscribeInfoEvent>>() {
@Override
public void onSuccess(List<SubscribeInfoEvent> subscribeInfoEvents) {
// Query successful - returns user profile information
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
// Query failed
}
});