Browse SDKs · Android
Platform
SDKsAndroid

Create a contact card message

Use createCardMessage to create a contact card message.

Copy

Construct a personal contact card message to share user profiles with other chat participants. Use CardElem to package the target user's userID, nickname, and avatar URL.

Code example

CardElem cardElem = new CardElem();
cardElem.setUserID("user_target");
cardElem.setNickname("Li Si");
cardElem.setFaceURL("https://example.com/avatar.png");

Message message = OpenIMClient.getInstance().messageManager.createCardMessage(cardElem);

Parameters

ParameterTypeRequiredDescription
cardElemCardElemYesContact card data model. Must specify the target user's ID userID, display name nickname, and avatar URL faceURL.

Return value

Returns the created Message object with contentType set to MessageType.CARD.

State changes after the call

  1. Local initialization: Initializes the local Message structure without sending data to the server or verifying user existence.
  2. Transmission: Call Send a message to deliver the card message to a single user or group.