Recently integrated rongyun IMkit SDK, there is a requirement to listen to all sent messages, according to the message type intercept or modify.

I checked the official document, but couldn’t find it. By chance, I saw a listener when I was looking at the API document and tried it, which could meet the requirements, so I recorded it again.

The specific method is the setSendMessageListener method of the RongIM class.

Here’s the code.

/** * Sets the listener for sending messages. * * @param Listener Listener for sending messages. */ RongIM.setSendMessageListener(new OnSendMessageListener() { @Override public Message onSend(Message message) { // If null is returned, the message will not be sent. } @override public Boolean onSent(Message Message, SentMessageErrorCode SentMessageErrorCode) {The method is sent after the Message is sent successfully. Return true, and the rest of the SDK logic will follow. Return true; }}).Copy the code