agora_chat_SDK  3.8.2
agorajavachatSDK
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
io.agora.chat.ChatMessage Class Reference
Inheritance diagram for io.agora.chat.ChatMessage:

Classes

enum  ChatType
 
enum  Direct
 
class  EMCallbackHolder
 
enum  Status
 
enum  Type
 

Public Member Functions

Status status ()
 
 ChatMessage (EMAMessage message)
 
void setStatus (Status status)
 
Type getType ()
 
MessageBody getBody ()
 
long getMsgTime ()
 
void setMsgTime (long msgTime)
 
long localTime ()
 
void setLocalTime (long serverTime)
 
boolean isNeedGroupAck ()
 
void setIsNeedGroupAck (boolean need)
 
int groupAckCount ()
 
void setGroupAckCount (int count)
 
void setBody (MessageBody body)
 
void addBody (MessageBody body)
 
String getFrom ()
 
void setFrom (String from)
 
void setTo (String to)
 
String getTo ()
 
String getMsgId ()
 
void setMsgId (String msgId)
 
synchronized void setMessageStatusCallback (CallBack callback)
 
String toString ()
 
void setAttribute (String attribute, boolean value)
 
void setAttribute (String attribute, int value)
 
void setAttribute (String attribute, long value)
 
void setAttribute (String attribute, JSONObject value)
 
void setAttribute (String attribute, JSONArray value)
 
void setAttribute (String attribute, String value)
 
boolean getBooleanAttribute (String attribute) throws ChatException
 
boolean getBooleanAttribute (String attribute, boolean defaultValue)
 
int getIntAttribute (String attribute, int defaultValue)
 
long getLongAttribute (String attribute, long defaultValue)
 
int getIntAttribute (String attribute) throws ChatException
 
long getLongAttribute (String attribute) throws ChatException
 
String getStringAttribute (String attribute) throws ChatException
 
String getStringAttribute (String attribute, String defaultValue)
 
JSONObject getJSONObjectAttribute (String attribute) throws ChatException
 
JSONArray getJSONArrayAttribute (String attribute) throws ChatException
 
ChatType getChatType ()
 
void setChatType (ChatType chatType)
 
int describeContents ()
 
void writeToParcel (Parcel out, int flags)
 
Object clone () throws CloneNotSupportedException
 
boolean isAcked ()
 
void setAcked (boolean isAcked)
 
boolean isDelivered ()
 
void setDelivered (boolean isDelivered)
 
boolean isUnread ()
 
void setUnread (boolean unread)
 
boolean isListened ()
 
void setListened (boolean isListened)
 
String getUserName ()
 
void setDeliverAcked (boolean isDeliverAcked)
 
int progress ()
 
void setProgress (int progress)
 
Direct direct ()
 
void setDirection (Direct dir)
 
String conversationId ()
 
Map< String, Object > ext ()
 

Static Public Member Functions

static ChatMessage createSendMessage (Type type)
 
static ChatMessage createReceiveMessage (Type type)
 
static ChatMessage createTxtSendMessage (String content, String username)
 
static ChatMessage createVoiceSendMessage (String filePath, int timeLength, String username)
 
static ChatMessage createVoiceSendMessage (Uri filePath, int timeLength, String username)
 
static ChatMessage createImageSendMessage (String filePath, boolean sendOriginalImage, String username)
 
static ChatMessage createImageSendMessage (Uri imgUri, boolean sendOriginalImage, String username)
 
static ChatMessage createVideoSendMessage (String videofilePath, String imageThumbPath, int timeLength, String username)
 
static ChatMessage createVideoSendMessage (Uri videofilePath, String imageThumbPath, int timeLength, String username)
 
static ChatMessage createVideoSendMessage (Uri videofilePath, Uri imageThumbPath, int timeLength, String username)
 
static ChatMessage createLocationSendMessage (double latitude, double longitude, String locationAddress, String username)
 
static ChatMessage createFileSendMessage (String filePath, String username)
 
static ChatMessage createFileSendMessage (Uri filePath, String username)
 

Static Public Attributes

static final Parcelable.Creator< ChatMessageCREATOR
 

Detailed Description

Message object, represent a sent/received message

Construct a new send text message

    ChatMessage msg = ChatMessage.createSendMessage(ChatMessage.Type.TXT);
    msg.setTo("user1");
    TextMessageBody body = new TextMessageBody("hello from hyphenate sdk");
    msg.addBody(body);

Construct a new receive text message

     ChatMessage msg = ChatMessage.createSendMessage(ChatMessage.Type.IMAGE);
     msg.setTo("user1");
     ImageMessageBody body = new ImageMessageBody(imageFileUrl);
     msg.addBody(body);

Member Function Documentation

void io.agora.chat.ChatMessage.addBody ( MessageBody  body)

Add a message body Only support add one now

Parameters
bodyThe message body
String io.agora.chat.ChatMessage.conversationId ( )

Get conversation id

Returns
Conversation id
static ChatMessage io.agora.chat.ChatMessage.createFileSendMessage ( String  filePath,
String  username 
)
static

Create a normal file send message

Parameters
filePathThe path of the file
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createFileSendMessage ( Uri  filePath,
String  username 
)
static

Create a normal file send message

Parameters
filePathThe path of the file
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createImageSendMessage ( String  filePath,
boolean  sendOriginalImage,
String  username 
)
static

Create a image send message

Parameters
filePathThe path of the image
sendOriginalImageWhether to send the original(if image greater than 100k sdk will be compressed)
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createImageSendMessage ( Uri  imgUri,
boolean  sendOriginalImage,
String  username 
)
static

Create a image send message

Parameters
imgUriThe uri of the image
sendOriginalImageWhether to send the original(if image greater than 100k sdk will be compressed)
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createLocationSendMessage ( double  latitude,
double  longitude,
String  locationAddress,
String  username 
)
static

Create a location send message

Parameters
latitudeThe latitude
longitudeThe longitude
locationAddressLocation details
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createReceiveMessage ( Type  type)
static

Create a new receive message

Parameters
typeThe message type
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createSendMessage ( Type  type)
static

Create a new send message

Parameters
typeThe message type
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createTxtSendMessage ( String  content,
String  username 
)
static

Create a text send message

Parameters
contentText content
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createVideoSendMessage ( String  videofilePath,
String  imageThumbPath,
int  timeLength,
String  username 
)
static

Create a video send message

Parameters
videofilePathThe path of the video file
imageThumbPathThe path of the thumbnail
timeLengthThe length of the video time, unit s
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createVideoSendMessage ( Uri  videofilePath,
String  imageThumbPath,
int  timeLength,
String  username 
)
static

Create a video send message

Parameters
videofilePathThe path of the video file
imageThumbPathThe path of the thumbnail
timeLengthThe length of the video time, unit s
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createVideoSendMessage ( Uri  videofilePath,
Uri  imageThumbPath,
int  timeLength,
String  username 
)
static

Create a video send message

Parameters
videofilePathThe path of the video file
imageThumbPathThe path of the thumbnail
timeLengthThe length of the video time, unit s
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createVoiceSendMessage ( String  filePath,
int  timeLength,
String  username 
)
static

Create a voice send message

Parameters
filePathThe path of the voice file
timeLengthThe time length of the voice(unit s)
usernameThe recipient(user or group) id
Returns
The message instance
static ChatMessage io.agora.chat.ChatMessage.createVoiceSendMessage ( Uri  filePath,
int  timeLength,
String  username 
)
static

Create a voice send message

Parameters
filePathThe uri of the voice file
timeLengthThe time length of the voice(unit s)
usernameThe recipient(user or group) id
Returns
The message instance
Direct io.agora.chat.ChatMessage.direct ( )

The message direction

Returns
See Direct
Map<String, Object> io.agora.chat.ChatMessage.ext ( )

Get message extension, return type is Map&#60;String, Object&#62;

Returns
Return message extension, return type is Map&#60;String, Object&#62; Object can be Boolean, Integer, Long, Float, Double, String If the input is JsonObject or JsonArray, which use setAttribute(String attribute, JSONObject json) to passed in, the Map.Entry.value type is String
MessageBody io.agora.chat.ChatMessage.getBody ( )

Get message body

Returns
Message body
boolean io.agora.chat.ChatMessage.getBooleanAttribute ( String  attribute) throws ChatException

Get a boolean type extra attribute

Parameters
attributeAttribute key
Returns
Attribute value
Exceptions
ChatException
boolean io.agora.chat.ChatMessage.getBooleanAttribute ( String  attribute,
boolean  defaultValue 
)

Get a boolean type extra attribute

Parameters
attributeAttribute key
defaultValuethe default value you want
Returns
Attribute value
ChatType io.agora.chat.ChatMessage.getChatType ( )

Get chat type

Returns
ChatType
String io.agora.chat.ChatMessage.getFrom ( )

Get the sender id

Returns
user id
int io.agora.chat.ChatMessage.getIntAttribute ( String  attribute,
int  defaultValue 
)

Get a int type extra attribute

Parameters
attributeAttribute key
defaultValueThe default value you want
Returns
Attribute value
int io.agora.chat.ChatMessage.getIntAttribute ( String  attribute) throws ChatException

Get a int type extra attribute

Parameters
attributeAttribute key
Returns
Attribute value
Exceptions
ChatException
JSONArray io.agora.chat.ChatMessage.getJSONArrayAttribute ( String  attribute) throws ChatException

Get a JSONArray type attribute

Parameters
attributeAttribute key
Returns
Attribute value
Exceptions
ChatException
JSONObject io.agora.chat.ChatMessage.getJSONObjectAttribute ( String  attribute) throws ChatException

Get a JSONObject type attribute

Parameters
attributeAttribute key
Returns
Attribute value
Exceptions
ChatException
long io.agora.chat.ChatMessage.getLongAttribute ( String  attribute,
long  defaultValue 
)

Get a long type extra attribute

Parameters
attributeAttribute key
defaultValueThe default value you want
Returns
Attribute value
long io.agora.chat.ChatMessage.getLongAttribute ( String  attribute) throws ChatException

Get long type extra attribute

Parameters
attributeAttribute key
Returns
Attribute value
Exceptions
ChatException
String io.agora.chat.ChatMessage.getMsgId ( )

Get message id

Returns
Message id
long io.agora.chat.ChatMessage.getMsgTime ( )

Get message timestamp(server time)

Returns
Message timestamp(server time)
String io.agora.chat.ChatMessage.getStringAttribute ( String  attribute) throws ChatException

Get a string type extra attribute

Parameters
attributeAttribute key
Returns
Attribute value
Exceptions
ChatException
String io.agora.chat.ChatMessage.getStringAttribute ( String  attribute,
String  defaultValue 
)

Get a string type extra attribute

Parameters
attributeAttribute key
defaultValueThe default value you want
Returns
Attribute value
String io.agora.chat.ChatMessage.getTo ( )

Get receiver name

Returns
Receiver name
Type io.agora.chat.ChatMessage.getType ( )

获取消息类型

Returns
消息类型

Get message chat type

Returns
Message chat type
String io.agora.chat.ChatMessage.getUserName ( )

Get the peer's id

Returns
Peer's id
int io.agora.chat.ChatMessage.groupAckCount ( )

Read ack number of group message

Returns
Read ack number of group message
boolean io.agora.chat.ChatMessage.isAcked ( )

whether to read ack by the other

Returns
whether to read
boolean io.agora.chat.ChatMessage.isDelivered ( )

Delivery Ack, check if the peer has received the message

Returns
Whether the peer has received the message
boolean io.agora.chat.ChatMessage.isListened ( )

Get whether the message has been listened

Returns
boolean io.agora.chat.ChatMessage.isNeedGroupAck ( )

Message if need group read ack

Returns
True: need group read ack; False: not need group read ack
boolean io.agora.chat.ChatMessage.isUnread ( )

Check if the message has been read

Returns
Whether the message has been read
long io.agora.chat.ChatMessage.localTime ( )

Get local timestamp

Returns
Local timestamp
int io.agora.chat.ChatMessage.progress ( )

Indicate message attachment upload or download progress, value ranges between 0-100 For message attachment's thumbnail, it doesn't has progress information

Returns
progress value
void io.agora.chat.ChatMessage.setAcked ( boolean  isAcked)

Sets whether the other has been read Not supposed to be called by app

Parameters
isAcked
void io.agora.chat.ChatMessage.setAttribute ( String  attribute,
boolean  value 
)

Set a boolean type extra attributes of the message

Parameters
attributeAttribute key
valueAttribute value
void io.agora.chat.ChatMessage.setAttribute ( String  attribute,
int  value 
)

Set a int type extra attributes of the message

Parameters
attributeAttribute key
valueAttribute value
void io.agora.chat.ChatMessage.setAttribute ( String  attribute,
long  value 
)

Set a long type extra attributes of the message

Parameters
attributeAttribute key
valueAttribute value
void io.agora.chat.ChatMessage.setAttribute ( String  attribute,
JSONObject  value 
)

Set a JSONObject type extra attributes of the message

Parameters
attributeAttribute key
valueAttribute value
void io.agora.chat.ChatMessage.setAttribute ( String  attribute,
JSONArray  value 
)

Set a JSONArray type extra attributes of the message

Parameters
attributeAttribute key
valueAttribute value
void io.agora.chat.ChatMessage.setAttribute ( String  attribute,
String  value 
)

Set a string type extra attributes of the message

Parameters
attributeAttribute key
valueAttribute value
void io.agora.chat.ChatMessage.setBody ( MessageBody  body)

set message body

Parameters
body
void io.agora.chat.ChatMessage.setChatType ( ChatType  chatType)

Set chat type The default is single chat ChatType#Chat

Parameters
chatTypesee ChatType
void io.agora.chat.ChatMessage.setDeliverAcked ( boolean  isDeliverAcked)

Set message deliver ack Not supposed to be called by app

Parameters
isDeliverAcked
void io.agora.chat.ChatMessage.setDelivered ( boolean  isDelivered)

Sets whether the message has been delivered Not supposed to be called by app

Parameters
isDelivered
void io.agora.chat.ChatMessage.setDirection ( Direct  dir)

Set message direction

Parameters
dirMessage direction, see Direct
void io.agora.chat.ChatMessage.setFrom ( String  from)

Set message sender id

Parameters
fromSender id
void io.agora.chat.ChatMessage.setGroupAckCount ( int  count)

Set read ack number of group message

Parameters
count
void io.agora.chat.ChatMessage.setIsNeedGroupAck ( boolean  need)

Set message if need group read ack

Parameters
need
void io.agora.chat.ChatMessage.setListened ( boolean  isListened)

Sets whether the other has been listened

Parameters
isListened
void io.agora.chat.ChatMessage.setLocalTime ( long  serverTime)

Set message local time

Parameters
serverTimeMessage local time
synchronized void io.agora.chat.ChatMessage.setMessageStatusCallback ( CallBack  callback)

Set message status callback Your app should set emaObject callback to get message status and then refresh the ui accordingly

Parameters
callback
void io.agora.chat.ChatMessage.setMsgId ( String  msgId)

Set local message id

Parameters
msgIdMessage id
void io.agora.chat.ChatMessage.setMsgTime ( long  msgTime)

Set message timestamp (server time)

Parameters
msgTimeMessage timestamp (server time)
void io.agora.chat.ChatMessage.setProgress ( int  progress)

Set message attachment upload or download progress, value ranges between 0-100 For app developing, it doesn't need to set progress

Parameters
progress
void io.agora.chat.ChatMessage.setStatus ( Status  status)

Set the status of the message

Parameters
statusStatus of the message
void io.agora.chat.ChatMessage.setTo ( String  to)

Sets the receiver ID of the message

Parameters
toThe receiver ID
Status io.agora.chat.ChatMessage.status ( )

Get the send/receive status of message

Returns
Send/receive status of message

Member Data Documentation

final Parcelable.Creator<ChatMessage> io.agora.chat.ChatMessage.CREATOR
static
Initial value:
= new Parcelable.Creator<ChatMessage>() {
public ChatMessage createFromParcel(Parcel in) {
ChatMessage msg = null;
try {
msg = new ChatMessage(in);
} catch (ChatException e) {
e.printStackTrace();
}
return msg;
}
public ChatMessage[] newArray(int size) {
return new ChatMessage[size];
}
}

The documentation for this class was generated from the following file: