Skip to main content

When sending a message, you can set the burn-after-reading duration lifeTimeAfterRead. The message is destroyed after it has been read for lifeTimeAfterRead milliseconds.

Code Example

MessageOptions o = new MessageOptions();
// Unit: milliseconds. The message is automatically deleted five minutes after being read. The default is 0, which disables deletion after reading.
o.setLifeTimeAfterRead(5 * 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, the recipient calls sendReadReceipt() to mark it as read.

For private messages, the countdown starts for both sender and recipient after the recipient reads the message.

For group messages, the recipient countdown starts after that user reads the message; the sender countdown starts after all other group members read it.

When the countdown starts, the SDK invokes onMessageDestroyTimeUpdate() and automatically sets Message.getDestroyTime() to the message read time plus lifeTimeAfterRead. Use this time to render the UI countdown.

Code Example

JIM.getInstance().getMessageManager().addDestroyListener("main", new IMessageManager.IMessageDestroyListener() {
@Override
public void onMessageDestroyTimeUpdate(String messageId, Conversation conversation, long destroyTime) {

}
});