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.
Visit https://doc.rentsoft.cn/ for detailed documentation and guides.
For the SDK reference, see https://doc.rentsoft.cn/sdks/quickstart/android.
If you are a new for our repository, just ignore this.
We had already moved most release libraries to Maven Central. So if you has some errors in build.gradle when build your project, you can replace the old repository to Maven Central in your build.gradle like this:
Before:
buildscript {
repositories {
...
maven { url 'https://open-im-online.rentsoft.cn:51000/repository/maven2/' }
google()
mavenCentral()
...
}
}
allprojects {
repositories {
...
maven { url 'https://open-im-online.rentsoft.cn:51000/repository/maven2/' }
google()
mavenCentral()
...
}
}
After:
buildscript {
repositories {
...
google()
mavenCentral()
...
}
}
allprojects {
repositories {
...
google()
mavenCentral()
...
}
}
Just make sure your project had already used Maven Central to get our libraries' dependency when you wanna to build project.
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'
The following examples demonstrate how to use the SDK.
package io.openim.android.sdk;
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);
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.
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 ๐จ
}
}๏ผ
You can find a demo Android app that uses the SDK in the open-im-android-demo repository.
- ๐ OpenIM Community
- ๐ OpenIM Interest Group
- ๐ Join our Slack community
- ๐ Join our wechat (ๅพฎไฟก็พค)
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 ๐.
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.
OpenIM is licensed under the Apache 2.0 license. See LICENSE for the full license text.