Skip to main content

🚀 Using the Demo​

We strongly recommend that you first run the framework-specific sample DEMO we have prepared for you. This will not only give you a firsthand experience of OpenIMSDK's features but will also assist you in quickly identifying and resolving issues during the actual integration process.

Integration Steps​

1. Add Dependencies​

implementation 'io.openim:android-sdk:latest@aar'
implementation 'io.openim:core-sdk:latest@aar'
implementation ''

2. Import Package​


3. Initialization​

InitConfig initConfig=new InitConfig(
Constant.getImApiUrl(),//SDK API address
Constant.getImWsUrl(),//SDK WebSocket address
getStorageDir(),//SDK database storage directory

application, //Application
new OnConnListener() {
public void onConnectFailed(long code, String error) {
//Connection to server failed

public void onConnectSuccess() {
//Successfully connected to the server

public void onConnecting() {
//Connecting to the server...

public void onKickedOffline() {
//The current user was kicked offline

public void onUserTokenExpired() {
//The login token has expired

4. Set Listener​

// Set listener
// The SDK uses the 'set' method, setting multiple times will replace the previous setting. It's recommended to use middleware and the 'add' method for callback execution distribution, see the demo's IMEvent class for reference

// Callback when current user's profile changes
OpenIMClient.getInstance().userInfoManager.setOnUserListener(info -> {});
// Listener for receiving new messages, read receipts, and message recalls.
OpenIMClient.getInstance().messageManager.setAdvancedMsgListener(new OnAdvanceMsgListener() { }
// Listener for changes in friendships
OpenIMClient.getInstance().friendshipManager.setOnFriendshipListener(new OnFriendshipListener() {}
// Listener for new or changed conversations
OpenIMClient.getInstance().conversationManager.setOnConversationListener(new OnConversationListener() {}
// Listener for changes in group relationships
OpenIMClient.getInstance().groupManager.setOnGroupListener(new OnGroupListener() {}
// Signaling listener
OpenIMClient.getInstance().signalingManager.setSignalingListener(new OnSignalingListener() {}

5. Login​

Note: Set the listener first, then login

OpenIMClient.getInstance().login(new OnBase<String>() {
public void onError(int code, String error) {

public void onSuccess(String data) {
//Other API calls must ensure that the login callback is successful before proceeding

}, userID, imToken);