Skip to main content

Typing Status

Applications can send the current user's typing status in a one-to-one chat. Upon receiving the notification, the recipient can display "xxx is typing" in the UI.

Sending Typing Status Messages

Call sendTypingStatus when the current user is typing text to send the current user's typing status.

RongIMClient.getInstance().sendTypingStatus(conversationType, targetId, typingContentType);
ParameterTypeDescription
conversationTypeConversationTypeConversation type. This interface only supports one-to-one chat types.
targetIdStringConversation ID.
typingContentTypeStringThe type name of the message being typed. For example, for a text message, pass the type name "RC:TxtMsg".

Listening for Typing Status

Applications can use setTypingStatusListener to set up a TypingStatusListener to listen for typing status notifications received in one-to-one chat conversations. When a typing status notification is received from the other party, the SDK will return the list of currently typing users and the message type through the onTypingStatusChanged callback method.

RongIMClient.setTypingStatusListener(new RongIMClient.TypingStatusListener() {
@Override
public void onTypingStatusChanged(Conversation.ConversationType type, String targetId, Collection<TypingStatus> typingStatusSet) {
// Only display if the conversation type and targetID of the typing status match the current conversation
if (type.equals(mConversationType) && targetId.equals(mTargetId)) {
// count represents the number of users currently typing in the conversation, currently only supports one-to-one chat
int count = typingStatusSet.size();
if (count > 0) {
Iterator iterator = typingStatusSet.iterator();
TypingStatus status = (TypingStatus) iterator.next();
String objectName = status.getTypingContentType();

MessageTag textTag = TextMessage.class.getAnnotation(MessageTag.class);
MessageTag voiceTag = VoiceMessage.class.getAnnotation(MessageTag.class);
// Match whether the other party is typing a text message or a voice message
if (objectName.equals(textTag.value())) {
// Display "The other party is typing"
mHandler.sendEmptyMessage(SET_TEXT_TYPING_TITLE);
} else if (objectName.equals(voiceTag.value())) {
// Display "The other party is speaking"
mHandler.sendEmptyMessage(SET_VOICE_TYPING_TITLE);
}
} else {
// No users are currently typing in the conversation, the title bar still displays the original title
mHandler.sendEmptyMessage(SET_TARGETID_TITLE);
}
}
}
});