Skip to main content

Page Event Listeners

IMKit supports listening to click and long-press events on the conversation list page and chat UI. Applications can intercept these events in corresponding methods to implement custom requirements.

Listening to Conversation List Page Events

IMKit provides the ConversationListBehaviorListener to monitor long-press and click events on conversation items and avatars in the conversation list.

Use the setConversationListBehaviorListener method of RongIM or IMCenter to set up the listener.

RongIM.setConversationListBehaviorListener(listener);

Long-Press Conversation Event

This method is triggered when a conversation item is long-pressed in the conversation list. By default, the SDK displays a menu.

boolean onConversationLongClick(Context context, View view, BaseUiConversation conversation)
ParameterTypeDescription
contextContextContext
viewViewThe view that triggered the event
conversationBaseUiConversationThe long-pressed conversation

Return true to handle the event customly; otherwise, return false to proceed with the SDK's default logic.

Click Conversation Event

This method is triggered when a conversation item is clicked in the conversation list. The SDK's default navigation logic is as follows:

  • For aggregated conversations: Navigate to the aggregated conversation list page.
  • For non-aggregated conversations: Navigate to the chat UI.
boolean onConversationClick(Context context, View view, BaseUiConversation conversation)
ParameterTypeDescription
contextContextContext
viewViewThe view that triggered the event
conversationBaseUiConversationThe clicked conversation

Return true to handle the event customly; otherwise, return false to proceed with the SDK's default logic.

Click Conversation Avatar Event

This method is triggered when a conversation avatar (icon) is clicked. The SDK does not handle this event by default.

boolean onConversationPortraitClick(Context context, Conversation.ConversationType conversationType, String targetId)
ParameterTypeDescription
contextContextContext
conversationTypeConversation.ConversationTypeConversation type
targetIdStringTarget ID

Return true to handle the event customly; otherwise, return false to ignore it.

Long-Press Conversation Avatar Event

This method is triggered when a conversation avatar (icon) is long-pressed. The SDK does not handle this event by default.

boolean onConversationPortraitLongClick(Context context, Conversation.ConversationType conversationType, String targetId)
ParameterTypeDescription
contextContextContext
conversationTypeConversation.ConversationTypeConversation type
targetIdStringTarget ID

Return true to handle the event customly; otherwise, return false to ignore it.

Listening to Chat UI Events

IMKit provides the ConversationClickListener to monitor click and long-press events on message items and avatars in the chat UI.

Use the setConversationClickListener method of RongIM or IMCenter to set up the listener.

IMCenter.setConversationClickListener(listener);

Click Message Event

boolean onMessageClick(Context context, View view, Message message);
ParameterTypeDescription
contextContextContext
viewViewThe view that triggered the event
messageMessageThe clicked message object

Return true to handle the event customly; otherwise, return false to proceed with the SDK's default logic.

Long-Press Message Event

boolean onMessageLongClick(Context context, View view, Message message);
ParameterTypeDescription
contextContextContext
viewViewThe view that triggered the event
messageMessageThe long-pressed message object

Return true to handle the event customly; otherwise, return false to proceed with the SDK's default logic.

Click User Avatar in Message Event

boolean onUserPortraitClick(
Context context,
Conversation.ConversationType conversationType,
UserInfo user,
String targetId);
ParameterTypeDescription
contextContextContext
conversationTypeConversation.ConversationTypeConversation type
userUserInfoThe clicked user's information
targetIdStringTarget ID

Return true to handle the event customly; otherwise, return false to proceed with the SDK's default logic.

Long-Press User Avatar in Message Event

This method is triggered when a user avatar (icon) in a message is long-pressed. By default, the SDK navigates to the @mention user selection interface.

boolean onUserPortraitLongClick(
Context context,
Conversation.ConversationType conversationType,
UserInfo user,
String targetId);
ParameterTypeDescription
contextContextContext
conversationTypeConversation.ConversationTypeConversation type
userUserInfoThe long-pressed user's information
targetIdStringTarget ID

Return true to handle the event customly; otherwise, return false to proceed with the SDK's default logic.

boolean onMessageLinkClick(Context context, String link, Message message);
ParameterTypeDescription
contextContextContext
linkStringThe clicked hyperlink
messageMessageThe message containing the hyperlink

Return true to handle the event customly; otherwise, return false to proceed with the SDK's default logic.

Click Read Receipt Status Event

boolean onReadReceiptStateClick(Context context, Message message);
ParameterTypeDescription
contextContextContext
messageMessageThe message with read receipt status

Return true to handle the event customly; otherwise, return false to proceed with the SDK's default logic.

Click Quick Reply Button Event

tip

Requires IMKit version ≥ 5.6.3.

If the IMKit Quick Reply feature is enabled, clicking the Quick Reply button in the chat UI will display quick replies. To intercept this event, return true to implement custom logic; otherwise, return false to proceed with the SDK's default behavior.

default boolean onQuickReplyClick(Context context) {
return false;
}