Skip to main content

When sending a message, you can set its lifetime. When the message expires, it is automatically destroyed by IM.

Code Example

MessageOptions o = new MessageOptions();
// Unit: milliseconds. This message will be automatically deleted after one day. The default is 0, which disables automatic destruction.
o.setLifeTime(24 * 60 * 60 * 1000);
TextMessage textMessage = new TextMessage("Text");
Conversation conversation = new Conversation(Conversation.ConversationType.PRIVATE, "111");
JIM.getInstance().getMessageManager().sendMessage(textMessage, conversation, o, new IMessageManager.ISendMessageCallback() {
@Override
public void onSuccess(Message message) {

}

@Override
public void onError(Message message, int errorCode) {

}
});

After a message is sent successfully, Message.getDestroyTime() is automatically set to the message send time plus its lifetime. Use this time to render the UI.