logo
In-app Chat
SDK Error Codes
On this page

Cancel Media Message Sending


Feature Overview

The ZIM SDK supports canceling messages containing local media files that are currently being sent. After a successful cancellation, the message status will change to "Failed to Send".

Note
  • Supported from version 2.22.0.
  • Only messages containing local media files of the following message types can be canceled: Multiple(10), Image(11), File(12), Audio(13), Video(14).

Cancel the Media Message Being Sent

When a user sends a message containing a local media file, due to the time required for file upload, the file upload can be terminated by calling cancelSendingMessage during this period.

Note

When a multi item messages containing both ordinary text and media files is canceled, the entire message (including ordinary text) will be canceled.

zim.setEventHandler(new ZIMEventHandler() {
    @Override
    public void onMessageSentStatusChanged(ZIM zim, ArrayList<ZIMMessageSentStatusChangeInfo> infos) {
        // Message sent status changed
    }
})

// User A sends a message, taking a single-chat file message as an example

String conversationID = "xxx" ; // Conversation ID

ZIMFileMessage message = new ZIMFileMessage("/storage/emulated/0/Android/data/packagename/picture/xxx.zip");
ZIMMessageSendConfig sendConfig = new ZIMMessageSendConfig();

zim.sendMessage(message, conversationID, ZIMConversationType.PEER, sendConfig, new ZIMMessageSentCallback() {
            @Override
            public void onMessageAttached(ZIMMessage message) {}

            @Override
            public void onMediaUploadingProgress(ZIMMediaMessage message, long currentFileSize, long totalFileSize) {
                // Cancel sending when the file is being uploaded
                zim.cancelSendingMessage(message, new ZIMSendingMessageCancelConfig(), new ZIMSendingMessageCancelledCallback() {
                    @Override
                    public  void onSendingMessageCancelled(ZIMError errorInfo) {}
                });        
            }
        });

Previous

Send and receive targeted messages in groups

Next

Call invitation (signaling)

On this page

Back to top