One-to-one message

It takes ordinary text messages as an example in the document. If there are other data format requirements, the text can be replaced with the JSON data defined by yourself

For example, if you want to send a picture, you can upload it to your own server or use a 3rd party image storage (such as Qi Niuyun, Alibaba Cloud OSS, etc.) to upload the image and send the URL.

4.1 Receiving one-to-one messages

Get the XHChatManager class instance and add the IXHChatManagerListener listener.

XHChatManager chatManager = XHClient.getInstance().getChatManager();
chatManager.addListener(new IXHChatManagerListener() {
@Override
public void onReceivedMessage(StarIMMessage message) {
//收到消息
}
@Override
public void onReceivedSystemMessage(XHIMMessage message) {
//收到系统消息
}
});

4.2 Sending one-to-one messages

The messages are divided into ordinary message(sendMessage) and online message(sendOnLineMessage).

“Normal message” refers to a normal chat message, which is cached when the user is offline, and it will be took all offline messages when they go online again.

“Online messages” are only received when the receiver is online, which are not cached.

Example:

//mTargetId : Target userId, it is recommended to use the id field of the user table.
//msg: Custom message
chatManager.sendMessage( mTargetId, msg);
chatManager.sendOnLineMessage( mTargetId, msg);