logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Send & Receive messages


ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of message management, allowing you to send and receive one-to-one, group, in-room messages, query message history, delete messages, and more. With the message management feature, you can meet different requirements of various scenarios such as social entertainment, online shopping, online education, interactive live streaming, and more.

This document describes how to send and receive messages with the ZIM SDK.

Message types

Message TypeDescriptionFeature and Scenario
ZIMTextMessage(1)The text message. A text message cannot exceed 32 KB in size, and up to 10 text messages can be sent per second per client.

Text messages are reliable and in order and can be stored as historical messages, applicable to one-to-one chats, group chats, and on-screen comments in chat rooms. After a room is disbanded, messages in it are not stored.

API: sendMessage

ZIMCommandMessage(2)The signaling message whose content can be customized. A signaling message cannot exceed 5 KB in size, and up to 10 signaling messages can be sent per second per client.

Signaling messages are applicable to signaling transmission (for example, co-hosting, virtual gifting, and course materials sending) in scenarios with a higher concurrency, such as chat rooms and online classrooms.

API: sendMessage

ZIMBarrageMessage(20)The on-screen comment in a chat room. An on-screen comment cannot exceed 5 KB in size, and there is no limit on the number of comments that can be sent per second per client.

On-screen comments are usually unreliable messages that are sent at a high frequency and can be discarded.

A high concurrency is supported, but reliability cannot be guaranteed.

API: sendMessage

ZIMImageMessage(11)The image message. Mainstream image formats, such as JPG, PNG, BMP, TIFF, GIF, and WebP, are supported. An image message cannot exceed 10 MB in size, and up to 10 image messages can be sent per second per client.

Image messages are reliable and in order and can be stored as historical messages (for 14 days by default), usually applicable to one-to-one chats, chat rooms, and group chats.

API: sendMessage

ZIMFileMessage(12)The file message. A file message contains a file of any format and cannot exceed 100 MB in size. Up to 10 file messages can be sent per second per client.
ZIMAudioMessage(13)The audio message. An audio message contains an MP3 or M4A audio of up to 300 seconds and cannot exceed 6 MB in size. Up to 10 audio messages can be sent per second per client.
ZIMVideoMessage(14)

The video message. A video message contains an MP4 or MOV video and cannot exceed 100 MB in size. Up to 10 video messages can be sent per second per client.

The width and height of the first frame of a video can be obtained after successful message sending only if the video is H.264- or H.265-encoded.

ZIMCombineMessage(100)Merge messages, there is no limit on message size, and the sending frequency of a single client is limited to 10 times/second.

Text messages are reliable and in order and can be stored as historical messages, applicable to real-time chat scenarios such as one-to-one chats, room, group chats, etc.

API: sendMessage

ZIMCustomMessage(200)The custom message. You can customize the message type and parse the message without using the ZIM SDK.

Custom messages are usually applicable to votes, solitaire, and video cards.

API: sendMessage

Send/Receive regular messages

Regular messages refer to the messages of the following message types: ZIMTextMessage and ZIMBarrageMessage.

Warning
  • To receive event callbacks (receive messages, get connection status, and receive a notification when Token is about to expire, etc.), you can set up the setEventHandler method and listen for related events.
  • When receiving messages, you need to determine the message is a Text message ZIMTextMessage or a Command message ZIMCommandMessage because these two message types are based on the basic message class ZIMMessage. You need to convert the basic message class to a concrete message type and then retrieve the message content from the message field.
  • When a message is received, it can be sorted using the message's orderKey. The larger the orderKey, the newer the message. And the number of unread messages will be updated automatically upon receiving.

Send/Receive messages

The following process shows how Client A sends messages to Client B:

  1. Client A and Client B create their own ZIM SDK instances, and set up an event handler setEventHandler to listen for the callback on the result of message sending onReceivePeerMessage.
  2. Client A and Client B log in to the ZIM SDK.
  3. Client A calls the sendMessage method, and set the converversationType to ZIMConversationTypePeer to send a one-to-one message to Client B.
  4. Client B listens for the onReceivePeerMessage callback to receive Client A's messages.
Warning

You can't send messages to yourself by calling the sendMessage method (when toConversationID = your ID). If you did so, the error code 6000001 will return.

Send messages

SampleCode
//  1. Create a ZIM SDK object with the AppID and AppSign you get, and the Application of the Android app.
ZIMAppConfig appConfig = new ZIMAppConfig();
appConfig.appID = 12345;  // The AppID you get.
appConfig.appSign = "appSign";   // The AppSign you get.
zim = ZIM.create(appConfig, application);

// 2. Set up a setEventHandler.
zim.setEventHandler(new ZIMEventHandler() {
    @Override
    public void onReceivePeerMessage(ZIM zim, ArrayList<ZIMMessage> messageList, String fromUserID) {
        // Callback on the one-on-one message received.
    }
});

// 3. Log in
ZIMUserInfo zimUserInfo = new ZIMUserInfo();
zimUserInfo.userID = "xxxx";
zimUserInfo.userName = "xxxx";
zim.login(zimUserInfo, new ZIMLoggedInCallback() {
    @Override
    public void onLoggedIn(ZIMError error) {
          // You can be told whether the login is successful according to the ZIMError.         
    }
 });

// 4. Send regular messages
String toConversationID = "xxxx1";

ZIMTextMessage zimMessage = new ZIMTextMessage();
zimMessage.message = "Message content";

ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Set the message priority.
config.priority = ZIMMessagePriority.LOW;
// Set up the configurations of the offline notifications.
// Offline push configuration of room messages is not supported. If you need to send room offline messages, please contact ZEGOCLOUD technical support team to activate relevant permissions.
ZIMPushConfig pushConfig = new ZIMPushConfig();
pushConfig.title = "Offline notification title";
pushConfig.content= "Offline notification content";
pushConfig.extendedData = "Extension info of the offline notification";
config.pushConfig = pushConfig;

// Set conversation type. Set it based on your conversation type.
// Send one-on-one messages. 
ZIMConversationType type = ZIMConversationType.Peer;

// Send group messages. 
ZIMConversationType type = ZIMConversationType.Gourp;

// Send in-room messages.
ZIMConversationType type = ZIMConversationType.Room;

// 5. Send messages.

zim.sendMessage(zimMessage, toConversationID, type,config, new ZIMMessageSentCallback() {
    @Override
    public void onMessageAttached(ZIMMessage zimMessage) {
    // You can use this callback to monitor whether the message is ready to be sent. This callback will be thrown only if the message passes the local basic parameter verification, otherwise an error will be thrown through the onMessageSent callback.
    }

    @Override
    public void onMessageSent(ZIMMessage zimMessage, ZIMError error) {
    // You can use this callback to monitor whether the message is ready to be sent. This callback will be thrown only if the message passes the local basic parameter verification, otherwise an error will be thrown through the onMessageSent callback.
    }
});
1
Copied!

Receive messages

Note
SampleCode
zim.setEventHandler(new ZIMEventHandler() {
    @Override
    public void onReceivePeerMessage(ZIM zim, ArrayList<ZIMMessage> messageList, String fromUserID) {
        // Callback for receiving one-to-one messages. 
        for (ZIMMessage zimMessage : messageList) {
           if (zimMessage instanceof ZIMTextMessage) {
                ZIMTextMessage zimTextMessage = (ZIMTextMessage) zimMessage;
                Log.e(TAG, "The text message you received:"+ zimTextMessage.message);
           } else if (zimMessage instanceof ZIMCommandMessage) {
                ZIMCommandMessage zimCommandMessage = (ZIMCommandMessage) zimMessage;
                Log.e(TAG, "The signaling message you received:"+ zimCommandMessage.message);
           }    
        }
    }

    @Override
    public void onReceiveGroupMessage(ZIM zim, ArrayList<ZIMMessage> messageList, String fromGroupID) {
        // Callback for receiving group messages. 
        for (ZIMMessage zimMessage : messageList) {
           if (zimMessage instanceof ZIMTextMessage) {
                ZIMTextMessage zimTextMessage = (ZIMTextMessage) zimMessage;
                Log.e(TAG, "The text message you received:"+ zimTextMessage.message);
           } else if (zimMessage instanceof ZIMCommandMessage) {
                ZIMCommandMessage zimCommandMessage = (ZIMCommandMessage) zimMessage;
                Log.e(TAG, "The signaling message you received:"+ zimCommandMessage.message);
           }    
        }
    }

    @Override
    public void onReceiveRoomMessage(ZIM zim, ArrayList<ZIMMessage> messageList, String fromRoomID) {
        // Callback for receiving in-room messages. 
        for (ZIMMessage zimMessage : messageList) {
           if (zimMessage instanceof ZIMTextMessage) {
                ZIMTextMessage zimTextMessage = (ZIMTextMessage) zimMessage;
                Log.e(TAG, "The text message you received:"+ zimTextMessage.message);
           } else if (zimMessage instanceof ZIMCommandMessage) {
                ZIMCommandMessage zimCommandMessage = (ZIMCommandMessage) zimMessage;
                Log.e(TAG, "The signaling message you received:"+ zimCommandMessage.message);
           }    
        }
    }
});
1
Copied!

Send/Receive rich media content

The ZIM SDK now supports sending and receiving messages of different rich media types, such as images, audio, video, and files. To send and receive rich media content, refer to the following:

  1. To send rich media content after login, you will need to specify the message type (image, file, audio, video) first and then the session type (one-on-one chat, room chat, group chat).
  2. For a receiver to receive and download the rich media content, set up and listen for related event callbacks based on the session type (one-on-one chat, room chat, group chat) after logging in.

Send rich media content

To send rich media content after login, call the sendMediaMessage method, and specify the message type (image, file, audio, video), the session type (one-on-one chat, room chat, group chat), and message related configurations as needed.

Warning
  • When sending rich media content, the file path to be sent must be in UTF-8 encoding format.
  • To send rich media content to a room/group, the sender must be in the room/group.
Untitled
// Send rich media content in one-on-one chat - Send images:
ZIMImageMessage message = new ZIMImageMessage("/storage/emulated/0/Android/data/packagename/picture/xxx.jpg");
// If a network URL is entered here, the SDK will pass through the path without ZIM background service processing. If both the network URL and the local path are entered, the SDK will prioritize the network URL that you want to use.
message.setLargeImageDownloadUrl("url");
message.setFileDownloadUrl("url");
message.setThumbnailDownloadUrl("url");
ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Set message priority. 
config.priority = ZIMMessagePriority.LOW;
// Set up the configurations of the offline notifications.
ZIMPushConfig pushConfig = new ZIMPushConfig();
pushConfig.title = "Offline notification title";
pushConfig.content= "Offline notification content";
pushConfig.extendedData = "Extension info of the offline notification";
config.pushConfig = pushConfig;

zim.sendMediaMessage(message, toConversationID, ZIMConversationType.PEER, config, new ZIMMediaMessageSentCallback() {
    @Override
    public void onMessageSent(ZIMMessage message, ZIMError errorInfo) {
     // You can use this callback to monitor whether the message is ready to be sent. This callback will be thrown only if the message passes the local basic parameter verification, otherwise an error will be thrown through the onMessageSent callback.。                    
    }

    @Override
    public void onMessageAttached(ZIMMediaMessage message){
    
    }

    @Override
    public void onMediaUploadingProgress(String fileUID, long currentFileSize, long totalFileSize, ZIMMediaMessage message) {
         // You can use this callback to monitor whether the message is sent successfully.              
    }
});
1
Copied!

Callback for the sending progress of rich media content

You will be notified of the sending progress of rich media content through the callback onMediaUploadingProgress.

Among which:

  • message: The content of the message being sent.
  • currentFileSiz: The size of the message that has been sent.
  • totalFileSize: The overall size of the message sent.

Receive rich media content

To receive the rich media content messages, do the following:

  1. Listen for the following callbacks based on the session type (one-on-one chat, room chat, group chat): onReceivePeerMessage, onReceiveRoomMessage, onReceiveGroupMessage.
  2. Call the downloadMediaFile method to download the rich media content.

When downloading rich media content, you need to specify the file type of the corresponding media messages first.

  • Image messages: You can choose to download the original file, large view, or thumbnail.
  • Files/Audio messages: Only original files/audio files can be downloaded.
  • Video messages: You can choose to download the original video file and the thumbnail of the first frame of the video.
SampleCode
// Receive rich media content in one-on-one chat - Receive images:
 @Override
    public void onReceivePeerMessage(ZIM zim, ArrayList<ZIMMessage> messageList, String fromUserID) {
        super.onReceivePeerMessage(zim, messageList, fromUserID);
        for (ZIMMessage message : messageList) {
            // You can tell by the Type which kind of message you are receiving. 
            if (message.getType() == ZIMMessageType.IMAGE) {
                // Receive images.
                ZIMImageMessage imageMessage = (ZIMImageMessage) message;
                zim.downloadMediaFile(imageMessage, ZIMMediaFileType.ORIGINAL_FILE, new ZIMMediaDownloadedCallback() {

                    @Override
                    public void onMediaDownloaded(ZIMMediaMessage message, ZIMError errorInfo) {
                        // Callback on the downloading completed.
                    }

                    @Override
                    public void onMediaDownloadingProgress(ZIMMediaMessage message, long currentFileSize, long totalFileSize) {
                        //  Callback on the downloading progress.
                    }
                });
            } else if (message.getType() == ZIMMessageType.VIDEO) {
                // Receive videos.
                ZIMVideoMessage videoMessage = (ZIMVideoMessage) message;
            } else if (message.getType() == ZIMMessageType.AUDIO) {
                // Receive audios.
                ZIMAudioMessage audioMessage = (ZIMAudioMessage) message;
            } else if (message.getType() == ZIMMessageType.FILE) {
                // Receive files.
                ZIMFileMessage fileMessage = (ZIMFileMessage) message;
            }
        }
    }
1
Copied!

Callback for the downloading progress of rich media content

You will be notified of the downloading progress of rich media content through the callback onMediaDownloadingProgress.

Among which:

  • message: The message content you are downloading.
  • currentFileSize: The size of messages that have been downloaded.
  • totalFileSize: The overall size of the download message.

Send/Receive signaling messages

The ZIM SDK now supports you to send and receive signaling messages. To do that, you can call the ZIMCommandMessage to define the message type you want to send, for example, your location information.

Note

This message type does not support offline push and local storage.

The following shows how to send custom messages to a specified user.

Send signaling messages

SampleCode


// Send signaling messages to a specified user.

// 1. Create a ZIM object and pass in appID, appSign and Application in Android
// For specific codes, please refer to the related codes of the above [Send & Receive messages - Send Messages].

// 2. Set setEventHandler callback
// For specific codes, please refer to the related codes of the above [Send & Receive messages - Send Messages].

// 3. Log in
// For specific codes, please refer to the related codes of the above [Send & Receive messages - Send Messages].

// 4. Send signaling messages.
String userID = "xxxx";

ZIMCommandMessage zimCustomMessage = new ZIMCommandMessage();
zimCustomMessage.message = new byte[]{0x1,0x2,0x1,0x2};

ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Set message priority.
config.priority = ZIMMessagePriority.LOW;
// For a room chat, offline notification is not supported. To use it, contact ZEGOCLOUD Technical Support to enable the feature first.

// Send one-on-one messages.
ZIMConversationType type = ZIMConversationType.Peer;

// Send group messages.
ZIMConversationType type = ZIMConversationType.Gourp;

// Send in-room messages.
ZIMConversationType type = ZIMConversationType.Room;

zim.sendMessage(zimCustomMessage, toConversationID, type,config, new ZIMMessageSentCallback() {
    @Override
    public void onMessageAttached(ZIMMessage zimMessage) {
        // You can use this callback to monitor whether the message is ready to be sent. This callback will be thrown only if the message passes the local basic parameter verification, otherwise an error will be thrown through the onMessageSent callback.
    }

    @Override
    public void onMessageSent(ZIMMessage zimMessage, ZIMError error) {
        // You can listen for the callback to know whether the message is sent successfully.
    }
});
1
Copied!

Receive signaling messages

SampleCode
// Receive signaling messages.
zim.setEventHandler(new ZIMEventHandler() {
    @Override
    public void onReceivePeerMessage(ZIM zim, ArrayList<ZIMMessage> messageList, String fromUserID) {
        // Callback on the custom message received.
        for (ZIMMessage zimMessage : messageList) {
            if (zimMessage instanceof ZIMCommandMessage) {
                ZIMCommandMessage zimCommandMessage = (ZIMCommandMessage) zimMessage;
                
           }    
        }
    }
});
1
Copied!

Send and receive custom message

The ZIM SDK supports developers in implementing the sending and receiving of custom message types. Developers can define their own message types using the ZIMCustomMessage object, such as voting, chain, video card, and more. Developers can follow these steps to implement the sending and receiving of custom messages.

Note
  • Only ZIM SDK version 2.8.0 and above supports sending custom type messages, receiving and viewing the content of custom type messages.
  • If the SDK version of the receiving end is between [2.0.0, 2.8.0), the custom message can be received, but the message type will be displayed as unknown and the information content cannot be obtained. To get this message, please upgrade the SDK to version 2.8.0 or above.
  • If the SDK version of the receiving end is version 1.x.x, you cannot receive custom messages or unknown messages.

Send custom messages

The interface used to send custom messages is sendMessage, which is the same as the interface used to send regular messages. Developers can refer to Send & Receive messages - Send messages to learn about this interface Parameter details.

Developers need to define custom type messages through the ZIMCustomMessage object.

Untitled
// Send a custom message to specified users in a one-to-one chat
// 1. Create a ZIM object and pass in appID, appSign and Application in Android
// For specific codes, please refer to the related codes of the above [Send & Receive messages - Send Messages].

// 2. Set setEventHandler callback
// For specific codes, please refer to the related codes of the above [Send & Receive messages - Send Messages].

// 3. Log in
// For specific codes, please refer to the related codes of the above [Send & Receive messages - Send Messages].

// 4. Send custom informatio
// Specify the user's ID
String userID = "xxxx";

// Customize the text content of the message
String message = "";

// Specific custom type
int subType = 100; 

// Customize the search field of the message.
String searchedContent = "";

ZIMCustomMessage zimCustomMessage = new ZIMCustomMessage(message,subType);

// Advanced property configuration for sending messages
ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Set message priority
config.priority = ZIMMessagePriority.LOW;

// Send one-to-one chat message 
// ZIMConversationType type = ZIMConversationType.Peer;

// Send group chat message
// ZIMConversationType type = ZIMConversationType.Gourp;

// Send room message
// ZIMConversationType type = ZIMConversationType.Room;

zim.sendMessage(zimCustomMessage, toConversationID, type,config, new ZIMMessageSentCallback() {
    @Override
    public void onMessageAttached(ZIMMessage zimMessage) {
        // You can use this callback to monitor whether the message is ready to be sent. This callback will be thrown only if the message passes the local basic parameter verification, otherwise an error will be thrown through the onMessageSent callback.            
    }

    @Override
    public void onMessageSent(ZIMMessage zimMessage, ZIMError error) {
        // You can use this callback to monitor whether the message is sent successfully.
    }
});
1
Copied!

Receive custom messages

The callback interface for receiving custom messages is the same as the callback interface for receiving regular messages. Please refer to Send & Receive messages - Receive messages for details on the specific interface.

The following is an example code for receiving custom messages in a one-on-one chat session:

Untitled
// User receives custom message in a one-to-one chat
zim.setEventHandler(new ZIMEventHandler() {
    @Override
    public void onReceivePeerMessage(ZIM zim, ArrayList<ZIMMessage> messageList, String fromUserID) {
        // Callback when receiving "one-to-one chat" message
        for (ZIMMessage zimMessage : messageList) {
            if (zimMessage instanceof ZIMCustomMessage) {
                ZIMCustomMessage zimCustomMessage = (ZIMCustomMessage) zimMessage;
                
           }    
        }
    }
});
1
Copied!

Send and Receive @ Messages

An "@" message refers to a message that contains the content of "@ + user". When a user is mentioned with an "@" message, they receive a strong notification.

Note

The "@" message is not a message type itself. A message can be both a text message or another type of message, and it can also be an "@" message.

Send @ messages

When calling sendMessage to send a message, you can use the following ZIMMessage parameters (can be used simultaneously) to mark a message as an "@" message:

  • `setMentionedUserIDs`: Notifies specific users (including users outside of the session) to view the message. The length of the userID list passed in should be up to 50. If you need to increase this limit, please contact the ZEGOCLOUD technical support team.
  • isMentionAll: Notifies all other users within the session to view the message.
Note

Only ZIM SDK version 2.14.0 and above supports sending messages with @ information.

Untitled
// The following is a sample code for a user to send an @ message in a single chat session:

// Create reminder user list
ArrayList<String> mentionArrayList = new ArrayList<>();

// Add a reminder to the user (the user does not need to be in the current session)
mentionArrayList.add("userId1");
mentionArrayList.add("userId2");

// message can be any type of message
// Call the interface to remind users in the list to view messages
message.setMentionedUserIDs(mentionArrayList);

// Remind all other users in the session to view the message
boolean isMentionAll = true;
message.setIsMentionAll(isMentionAll);

ZIMMessageSendConfig config = new ZIMMessageSendConfig();
// Set message priority
config.priority = ZIMMessagePriority.LOW;

// Whether to forcefully push the notification to the alerted user (regardless of whether the other party has enabled Do Not Disturb mode), the default is fasle;
config.isNotifyMentionedUsers = true;

// Take sending a one-to-one chat message as an example
ZIMConversationType type = ZIMConversationType.Peer;

zim.sendMessage(message,"conv_id", type, config, new ZIMMessageSentCallback() {
    @Override
    public void onMessageAttached(ZIMMessage zimMessage) {
        // You can use this callback to monitor whether the message is ready to be sent. This callback will be thrown only if the message passes the local basic parameter verification, otherwise an error will be thrown through the onMessageSent callback.           
    }

  @Override
    public void onMessageSent(ZIMMessage zimMessage, ZIMError error) {
         // Developers can use this callback to monitor whether the message is sent successfully.
    }
}];

1
Copied!

Receive @ messages

The callback interface for receiving @ messages is the same as the callback interface for receiving regular messages. Please refer to Send & Receive messages - Receive messages for details on the specific interface.

After receiving a message, developers can implement corresponding functionalities based on their business logic, such as highlighting, etc.

Note
  • Only ZIM SDK versions 2.14.0 and above support receiving and viewing the content of @ messages.
  • If the SDK version on the receiving end is between [2.0.0, 2.14.0), the received messages and conversations will not contain @ information.
  • If the SDK version on the receiving end is version 1.x.x, @ messages cannot be received.

Receive mentionedInfoList

After users within a session are mentioned, developers can passively or actively retrieve mentionedInfoList.

mentionedInfoList contains the corresponding message ID, sender userID, and the type of ZIMMessageMentionedType.Developers can use this information to implement various business logics, such as marking conversations.

Passive retrieval

When a user is mentioned, the onConversationChanged will be received, allowing you to retrieve the latest mentionedInfoListfor the current ZIMConversation.

Untitled
@Override
  public void onConversationChanged(
      ZIM zim, ArrayList<ZIMConversationChangeInfo> conversationChangeInfoList) {
      // conversationChangeInfoList You can get the mentionInfoList in the conversation that received the reminder
  }
1
Copied!

Active retrieval

If you use queryConversationList or queryConversation o actively fetch conversations, you can also retrieve the mentionedInfoList within the conversation. Refer to the following example code:

Untitled
ArrayList<ZIMMessageMentionedInfo> mentionedInfoList = conversation.mentionedInfoList;
1
Copied!

Clearing mentionedInfoList of a conversation

After receiving @ messages, users need to clear the mentionedInfoList of a conversation to stop receiving notifications.

The interface for clearing the mentionedInfoList is the same as clearing the unread message count of a conversation:

Get reminder user list

All users in the session can call the getMentionedUserIDs interface. Get the specific reminder user list, but this interface can only return the user list passed in by calling the setMentionedUserIDs interface.

Untitled
ArrayList<String> userIds = message.getMentionedUserIDs();
1
Copied!

Confirm whether it is a reminder for all members

All users within the conversation can use the isMentionAll parameter of ZIMMessageto determine whether it is a reminder for all members.

Untitled
boolean isMentionAll = message.isMentionAll();
1
Copied!

Send and receiving broadcast messages

ZIM allows you to send messages to all online users of your app from the server side, and the targeted users will receive the messages through the client side.

Send messages to all users from the server side

Please refer to the server-side API documentation Push message to all user to learn how to send messages to all users from the server side.

Receive broadcast messages sent from the server side

Note
  • Only ZIM SDK versions 2.10.0 and above support receiving and viewing the content of broadcast messages sent from the server side.
  • If the SDK version on the receiving end is between [2.0.0, 2.10.0), broadcast messages sent from the server side cannot be received. If you need to access this message, please upgrade the SDK to version 2.10.0 or above.

Through the onBroadcastMessageReceived callback, you can receive push messages from all members.

Sample code:

Untitled
// User receives broadcast messages 
public void onBroadcastMessageReceived(ZIM zim, ZIMMessage message) {
  super.onBroadcastMessageReceived(zim, message);
    // Receive broadcast messages from all members
}
1
Copied!

Forward message

The ZIM SDK supports forwarding messages in one of the following ways:

  • Combining messages and forwarding the combined message.
  • Forwarding messages one by one.

For more information, see Forward messages.

Receive Tips message

ZIM SDK supports converting user operations within a session into Tips messages. When a related operation occurs, ZIM SDK will send a Tips message to the session to notify. For details, please refer to Receive tip messages.

Listen for the message status

On a weak network condition, this may happen: the ZIM SDK doesn't receive the response from the server for some reason (e.g., packet loss), while the message is successfully sent. In this case, the ZIM SDK considers the message sending failed due to the reply timeout, but the message is actually sent successfully, which results in message status confusion. To solve this and Clarify the message status, the SDK 2.6.0 or later now allows you to listen for the onMessageSentStatusChanged callback to receive the changes of the message status. And we now have three different message statuses: Sending, Success, and Failed. You can know whether your message is sent successfully by the status, and implement your event handling logic as needed.

Untitled
//  Listen for the message status 
zim.setEventHandler(new ZIMEventHandler() {
    @Override
    public void onMessageSentStatusChanged(
        ZIM zim, ArrayList<ZIMMessageSentStatusChangeInfo> messageSentStatusChangeInfoList) {
            // You can listen for the callback on the changes of message status here.
}
});
1
Copied!

Previous

Manage group members

Next

Get message history