Business Card Message
Users can send personal business cards through the IMKit Business Card Plugin. The message will appear in the message list component of the conversation UI. By default, the plugin sends a message containing the business card content object ContactMessage
(type identifier: RC:CardMsg
).
The default conversation UI in IMKit does not enable the business card message feature. To use this feature, integrate the IMKit Business Card Plugin and provide the data to be displayed and sent.
Usage
The IMKit Business Card Plugin only supports source code integration.
-
Download the RC open-source repository (GitHub · Gitee), and copy the
contactcard
directory to your project directory. Ensure the plugin version matches the current SDK version. -
Add the following configuration to the
settings.gradle
file in your project root directory.include ':contactcard'
-
Add the dependency in your app's
build.gradle
.implementation project(path: ':contactcard')
-
Before entering the conversation UI, implement the business card info provider and the callback method for clicking business card messages in the conversation UI.
// Business card info provider
IContactCardInfoProvider contactCardInfoProvider = new IContactCardInfoProvider() {
@Override
public void getContactAllInfoProvider(IContactCardInfoCallback contactInfoCallback) {
// Retrieve all business card lists and pass them to the business card module via contactInfoCallback
imInfoProvider.getAllContactUserInfo(contactInfoCallback); // Pseudo-code, to be implemented by the app layer.
}
@Override
public void getContactAppointedInfoProvider(String userId, String name, String portrait, IContactCardInfoCallback contactInfoCallback) {
// Retrieve business card info for a specific user
imInfoProvider.getContactUserInfo(userId, contactInfoCallback); // Pseudo-code, to be implemented by the app layer.
}
};
IContactCardClickListener contactCardClickListener = new IContactCardClickListener() {
// This callback is triggered when clicking a business card message in the conversation UI. Implement navigation logic here.
@Override
public void onContactCardClick(View view, ContactMessage content) {
// Example: Navigate to the user detail page
Context activityContext = view.getContext();
Intent intent = new Intent(activityContext, UserDetailActivity.class);
intent.putExtra(IntentExtra.STR_TARGET_ID, content.getId());
activityContext.startActivity(intent);
}
}; -
Register the business card module
ContactCardExtensionModule
with IMKit's input areaRongExtension
viaRongExtensionManager
. The business card module registersContactMessage
with IMLib and adds the business card pluginContactCardPlugin
to the extension panel. Call this method after SDK initialization and before entering the conversation UI. Recommended to configure globally during the app lifecycle.RongExtensionManager.getInstance().registerExtensionModule(new ContactCardExtensionModule(contactCardInfoProvider, contactCardClickListener));
Sending Business Card Messages
Users can click the +
button on the right side of the input bar to expand the extension panel, then click the business card icon to send a business card.

Customization
The business card plugin internally defines the business card message content class ContactMessage.java and the business card message display template ContactMessageItemProvider.java.
Customizing Business Card Message UI
To modify the built-in message style, implement your own message display template class and provide it to the SDK to replace the default business card message display template.
All message templates inherit from BaseMessageItemProvider<CustomMessage>
. Custom message display templates must also inherit from BaseMessageItemProvider<CustomMessage>
. For details, see Modifying Message Display Styles.
Alternatively, you can directly replace the style resources, string resources, and icon resources referenced in the business card message display template. Refer to the resources used in ContactMessageItemProvider.java in the IMKit source code.