Browse SDKs · Android
SDKsAndroid

Open a conversation

Use getOneConversation() to retrieve one conversation by user or group.

Copy

getOneConversation() retrieves one conversation by user or group and is suitable when opening a chat from a contact, user profile, or group profile. Pass the peer user ID for a one-to-one chat and the group ID for a group chat.

OpenIMClient.getInstance().conversationManager.getOneConversation(
    new OnBase<ConversationInfo>() {
        @Override
        public void onSuccess(ConversationInfo conversation) {
            // conversation contains the target conversation profile.
        }

        @Override
        public void onError(int code, String error) {
            // code and error describe the failure.
        }
    },
    sourceId,
    ConversationType.SINGLE_CHAT
);

sourceId is the peer userID for a one-to-one chat and groupID for a group chat. Use ConversationType.GROUP_CHAT or ConversationType.SUPER_GROUP_CHAT for a group according to its type.

The callback returns ConversationInfo. To receive newly added or changed conversations, see Get the conversation list for how to set OnConversationListener.