Browse SDKs · Android
Platform
SDKsAndroid

Send a message without OSS

Use sendMessageNotOss to send a media message whose resources were uploaded by your application.

Copy

Transmit a media message that already contains valid remote URLs, bypassing the SDK's built-in OSS upload pipeline. This method is typically used in conjunction with messages created from remote URLs (such as images, audio, video, or files created with create*MessageByURL). If the message was initialized from a local filesystem path, call the standard Send a message method instead.

Code example

String peerUserID = "user_b";
OfflinePushInfo offlinePushInfo = new OfflinePushInfo();

OpenIMClient.getInstance().messageManager.sendMessageNotOss(
    new OnMsgSendCallback() {
        @Override
        public void onProgress(long progress) {
            // Upload progress is typically not triggered since resources are already hosted
        }

        @Override
        public void onSuccess(Message sentMessage) {
            // Update local message state using sentMessage.getClientMsgID()
        }

        @Override
        public void onError(int code, String error) {
            // Handle send error and allow retry
        }
    },
    message,
    peerUserID,
    null,
    offlinePushInfo
);

Parameters

ParameterTypeRequiredDescription
callbackOnMsgSendCallbackYesCallback handler for message delivery events.
messageMessageYesThe message object to transmit, typically generated by a create*MessageByURL method.
recvUidStringConditionalRecipient user ID for single chat. Pass null for group chat.
recvGidStringConditionalTarget group ID for group chat. Pass null for single chat.
offlinePushInfoOfflinePushInfoNoCustom offline push notification payload. Pass null for default push configuration.

Return value

Upon success, onSuccess returns the transmitted Message object.

State changes after the call

  1. Callback confirmation: The onSuccess callback indicates that the server accepted the message. The client should update the message status in the UI using clientMsgID.
  2. Asynchronous event delivery: Receiving clients receive the message asynchronously via OnAdvanceMsgListener.onRecvNewMessage. See Receive messages for details.