Home

Awesome

Android Client SDK for OpenIM ๐Ÿ‘จโ€๐Ÿ’ป๐Ÿ’ฌ

Use this SDK to add instant messaging capabilities to your Android app. By connecting to a self-hosted OpenIM server, you can quickly integrate instant messaging capabilities into your app with just a few lines of code.

The underlying SDK core is implemented in OpenIM SDK Core. Using gomobile, it can be compiled into an AAR file for Android integration. Android interacts with the OpenIM SDK Core through JSON, and the SDK exposes a re-encapsulated API for easy usage. In terms of data storage, Android utilizes the SQLite layer provided internally by the OpenIM SDK Core.

Documentation ๐Ÿ“š

Visit https://doc.rentsoft.cn/ for detailed documentation and guides.

For the SDK reference, see https://doc.rentsoft.cn/sdks/quickstart/android.

Installation ๐Ÿ’ป

Adding repositories

   maven { url 'https://open-im-online.rentsoft.cn:51000/repository/maven2/' }

Adding Dependencies

   implementation 'io.openim:android-sdk:3.4.1@aar'
   implementation 'io.openim:core-sdk:3.4.1-alpha.4@aar'
   implementation 'com.google.code.gson:gson:2.9.0'

Usage ๐Ÿš€

The following examples demonstrate how to use the SDK.

Importing the SDK and initialize

package io.openim.android.sdk;

Initialize

  InitConfig initConfig = new InitConfig("Your IM server address",
            "Your IM server socket address", getStorageDir()); //Storage path
        initConfig.isLogStandardOutput = true;

        ///IM ๅˆๅง‹ๅŒ–
        OpenIMClient.getInstance().initSDK('Your Application',
            initConfig, IMEvent.getInstance().connListener);

Logging In and Listening for Connection Status

Note1: You need to set up the listeners first and then log in.

// Set listener
 //User Profile Change Listener
 OpenIMClient.getInstance().userInfoManager.setOnUserListener(new OnUserListener() { });
 //Message-related Listener
 OpenIMClient.getInstance().messageManager.setAdvancedMsgListener(new OnAdvanceMsgListener() {});
 //Friendship Status Change Listener
 OpenIMClient.getInstance().friendshipManager.setOnFriendshipListener(new OnFriendshipListener() {});
 //Conversation-related Listener
 OpenIMClient.getInstance().conversationManager.setOnConversationListener(new OnConversationListener() {});
 //Group-related Listener
 OpenIMClient.getInstance().groupManager.setOnGroupListener(new OnGroupListener() { });

// Retrieve the profile of the currently logged-in user
 OpenIMClient.getInstance().login(new OnBase<String>() {
                            @Override
                            public void onError(int code, String error) {
                                IView.err(error);
                            }

                            @Override
                            public void onSuccess(String data) {
                                //Cache login information and start a delightful chat
                   
                            }
                        }, userID, token);

To log into the IM server, you need to create an account and obtain a user ID and token. Refer to the access token documentation for details.

Receiving and Sending Messages ๐Ÿ’ฌ

OpenIM makes it easy to send and receive messages. By default, there is no restriction on having a friend relationship to send messages (although you can configure other policies on the server). If you know the user ID of the recipient, you can conveniently send a message to them.

//Send
Message  msg = OpenIMClient.getInstance().messageManager.createTextMessage("hello openim");
OpenIMClient.getInstance().messageManager.sendMessage(new OnMsgSendCallback() {
            @Override
            public void onError(int code, String error) {
             // Failed to send message โŒ
            }

            @Override
            public void onProgress(long progress) {
             //Sending...
            }

            @Override
            public void onSuccess(Message message) {
             // Message sent successfully โœ‰๏ธ	

            }
        }, msg, userID, groupID, null);


//Receive
OpenIMClient.getInstance().messageManager.setAdvancedMsgListener(new OnAdvanceMsgListener(){
  @Override
            public void onRecvNewMessage(Message msg) {
                // Received new message ๐Ÿ“จ
            }
}๏ผ‰

Examples ๐ŸŒŸ

You can find a demo Android app that uses the SDK in the open-im-android-demo repository.

Community :busts_in_silhouette:

Community Meetings :calendar:

We want anyone to get involved in our community and contributing code, we offer gifts and rewards, and we welcome you to join us every Thursday night.

Our conference is in the OpenIM Slack ๐ŸŽฏ, then you can search the Open-IM-Server pipeline to join

We take notes of each biweekly meeting in GitHub discussions, Our historical meeting notes, as well as replays of the meetings are available at Google Docs :bookmark_tabs:.

Who are using OpenIM :eyes:

Check out our user case studies page for a list of the project users. Don't hesitate to leave a ๐Ÿ“comment and share your use case.

License :page_facing_up:

OpenIM is licensed under the Apache 2.0 license. See LICENSE for the full license text.