Skip to main content

Download Media Message Files

The SDK provides the capability to download multimedia files, supporting the download of files via the URLs contained within media messages.

Download Media Files from Media Messages

If the Message object contains media message content (i.e., Message#getContent() returns media message content such as FileMessage, SightMessage, ImageMessage, GIFMessage, HQVoiceMessage, etc., which includes the media file URL), you can use downloadMediaMessage to download the media file.

RongCoreClient.getInstance().downloadMediaMessage(message, new IRongCallback.IDownloadMediaMessageCallback() {
@Override
public void onSuccess(Message message) {

}

@Override
public void onProgress(Message message, int progress) {

}

@Override
public void onError(Message message, IRongCoreEnum.CoreErrorCode code) {

}

@Override
public void onCanceled(Message message) {

}
});

Retrieve Current Download File Information

During the process of downloading a multimedia file using downloadMediaMessage, you can call getDownloadInfo to obtain details such as the total file size and storage path. This method only returns accurate information while the download is in progress. Once the download is complete, calling this method will return null.

tag is a unique identifier for the file, and you can use the messageId string.

String tag = message.getMessageId();

RongCoreClient.getInstance().getDownloadInfo(tag, new IRongCoreCallback.ResultCallback<DownloadInfo>() {
@Override
public void onSuccess(DownloadInfo downloadInfo) {

}

@Override
public void onError(IRongCoreEnum.CoreErrorCode code) {

}
});

Cancel Downloading a Multimedia File

Use cancelDownloadMediaMessage to cancel the download of a multimedia file. You need to pass in the Message object that is currently being downloaded.

RongCoreClient.getInstance().cancelDownloadMediaMessage(message, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {

}

@Override
public void onError(IRongCoreEnum.CoreErrorCode code) {

}
});

Pause Downloading a Multimedia File

Pause the download of a multimedia message.

RongCoreClient.getInstance().pauseDownloadMediaMessage(message, new IRongCoreCallback.OperationCallback() {
@Override
public void onSuccess() {

}

@Override
public void onError(IRongCoreEnum.CoreErrorCode code) {

}
});