public class EMMessage
extends java.lang.Object
implements java.lang.Cloneable
构造一条文本发送消息 construct a new send text message
EMMessage msg = EMMessage.createSendMessage(EMMessage.Type.TXT); msg.setReceipt("user1"); TextMessageBody body = new TextMessageBody("hello from easemob sdk"); msg.addBody(body);
构造一条图片消息 construct a new recv text message
EMMessage msg = EMMessage.createSendMessage(EMMessage.Type.IMAGE); msg.setReceipt("user1"); ImageMessageBody body = new ImageMessageBody(imageFileUrl); msg.addBody(body);
限定符和类型 | 类和说明 |
---|---|
static class |
EMMessage.ChatType
聊天类型:单聊,群聊,聊天室
chat type : private chat, group chat, chat room
|
static class |
EMMessage.Direct
消息的方向类型:区分是发送消息还是接收到的消息
message direction
|
static class |
EMMessage.Status
消息的发送/接收状态:成功,失败,发送/接收过程中,创建成功待发送
message status
|
static class |
EMMessage.Type
消息类型:文本,图片,视频,位置,语音,文件
message type:
|
限定符和类型 | 字段和说明 |
---|---|
static <any> |
CREATOR |
EMMessage.Direct |
direct
消息的方向:发送还是接收
|
boolean |
isAcked
对接收到的消息,标示系统是否发送了消息回执
对发送的消息,表示系统是否收到对方的已读回执
|
boolean |
isDelivered
对接收到的消息,标示系统是否发送了送达回执
对发送的消息,表示系统是否收到对方的送达回执
|
int |
progress
语音图片等消息的下载进展,用于UI 展示
|
EMMessage.Status |
status
消息的状态
|
限定符和类型 | 方法和说明 |
---|---|
void |
addBody(MessageBody body)
添加消息体.
|
java.lang.Object |
clone() |
static EMMessage |
createFileSendMessage(java.lang.String filePath,
java.lang.String username)
创建一个普通文件发送消息
|
static EMMessage |
createImageSendMessage(java.lang.String filePath,
boolean sendOriginalImage,
java.lang.String username)
创建一个图片发送消息
|
static EMMessage |
createLocationSendMessage(double latitude,
double longitude,
java.lang.String locationAddress,
java.lang.String username)
创建一个位置发送消息
|
static EMMessage |
createReceiveMessage(EMMessage.Type type)
创建一个接收消息
create a new recv message
|
static EMMessage |
createSendMessage(EMMessage.Type type)
创建一个发送消息
create a new send message
|
static EMMessage |
createTxtSendMessage(java.lang.String content,
java.lang.String username)
创建一个文本发送消息
|
static EMMessage |
createVideoSendMessage(java.lang.String videofilePath,
java.lang.String imageThumbPath,
int timeLength,
java.lang.String username)
创建一个视频发送消息
|
static EMMessage |
createVoiceSendMessage(java.lang.String filePath,
int timeLength,
java.lang.String username)
创建一个语言发送消息
|
int |
describeContents() |
MessageBody |
getBody()
获取消息的body
get message body
|
boolean |
getBooleanAttribute(java.lang.String attribute)
获取 boolean 类型扩展属性
|
boolean |
getBooleanAttribute(java.lang.String attribute,
boolean defaultValue)
获取 boolean 类型扩展属性
|
EMMessage.ChatType |
getChatType()
获取聊天类型
|
int |
getError()
返回发送消息失败后的error
|
java.lang.String |
getFrom()
获取消息发送者的用户名
get sender name
|
int |
getIntAttribute(java.lang.String attribute)
获取 int 类型扩展属性
|
int |
getIntAttribute(java.lang.String attribute,
int defaultValue)
获取 int 类型扩展属性
|
JSONArray |
getJSONArrayAttribute(java.lang.String attribute)
获取 JSONArray 类型扩展属性
|
JSONObject |
getJSONObjectAttribute(java.lang.String attribute)
获取 JSONObject 类型扩展属性
|
long |
getLongAttribute(java.lang.String attribute)
获取 long 类型扩展属性
|
long |
getLongAttribute(java.lang.String attribute,
long defaultValue)
获取 long 类型扩展属性
|
java.lang.String |
getMsgId()
获取消息的id'=
get message id
|
long |
getMsgTime()
获取消息的时间
get message time stamp
|
java.lang.String |
getStringAttribute(java.lang.String attribute)
获取 String 类型扩展属性
|
java.lang.String |
getStringAttribute(java.lang.String attribute,
java.lang.String defaultValue)
获取 String 类型扩展属性
|
java.lang.String |
getTo()
获取消息接收者的用户名
get receiver name
|
EMMessage.Type |
getType()
获取消息类型
get message chat type
|
java.lang.String |
getUserName()
获取通话对象
|
boolean |
isAcked() |
boolean |
isDelivered() |
boolean |
isListened()
获取语音是否已听
|
boolean |
isUnread() |
void |
setAcked(boolean isAcked) |
void |
setAttribute(java.lang.String attribute,
boolean value)
设置消息的boolean 类型扩展属性
|
void |
setAttribute(java.lang.String attribute,
int value)
设置消息的int 类型扩展属性
|
void |
setAttribute(java.lang.String attribute,
JSONArray json)
设置消息的 JSONArray 类型扩展属性
|
void |
setAttribute(java.lang.String attribute,
JSONObject json)
设置消息的 JSONObject 类型扩展属性
|
void |
setAttribute(java.lang.String attribute,
long value)
设置消息的long 类型扩展属性
|
void |
setChatType(EMMessage.ChatType chatType)
设置聊天类型, 缺省为单聊 ChatType.Chat
|
void |
setDelivered(boolean isDelivered) |
void |
setFrom(java.lang.String from)
设置消息发送者
set sender name
|
void |
setListened(boolean isListened)
设置语音是否已听
|
void |
setMessageStatusCallback(EMCallBack callBack)
设置消息状态改变的回调
set message status callback, your app should set this callback to get message status and then refresh the ui accordingly
|
void |
setMsgId(java.lang.String msgId)
set local message id
|
void |
setMsgTime(long msgTime)
设置消息的发送或者接收时间
set message time stamp
|
void |
setReceipt(java.lang.String username) |
void |
setTo(java.lang.String to)
设置消息
set receiver name
|
void |
setType(EMMessage.Type type) |
void |
setUnread(boolean unread) |
java.lang.String |
toString() |
void |
writeToParcel(Parcel out,
int flags) |
public EMMessage.Direct direct
public EMMessage.Status status
public boolean isAcked
public boolean isDelivered
public transient int progress
public static final <any> CREATOR
public EMMessage.Type getType()
public MessageBody getBody()
public long getMsgTime()
public void setMsgTime(long msgTime)
msgTime
- public static EMMessage createSendMessage(EMMessage.Type type)
type
- 消息类型public static EMMessage createReceiveMessage(EMMessage.Type type)
type
- 消息类型public static EMMessage createTxtSendMessage(java.lang.String content, java.lang.String username)
content
- 文本内容username
- 消息接收人或群idpublic static EMMessage createVoiceSendMessage(java.lang.String filePath, int timeLength, java.lang.String username)
filePath
- 语音文件路径timeLength
- 语音时间长度(单位秒)username
- 消息接收人或群idpublic static EMMessage createImageSendMessage(java.lang.String filePath, boolean sendOriginalImage, java.lang.String username)
filePath
- 图片路径sendOriginalImage
- 是否发送原图(默认大于100K的图片sdk会进行压缩)username
- 消息接收人或群idpublic static EMMessage createVideoSendMessage(java.lang.String videofilePath, java.lang.String imageThumbPath, int timeLength, java.lang.String username)
videofilePath
- 视频文件路径imageThumbPath
- 视频第一帧图缩略图timeLength
- 视频时间长度(单位秒)username
- 消息接收人或群idpublic static EMMessage createLocationSendMessage(double latitude, double longitude, java.lang.String locationAddress, java.lang.String username)
latitude
- 纬度longitude
- 经度locationAddress
- 位置详情username
- 消息接收人或群idpublic static EMMessage createFileSendMessage(java.lang.String filePath, java.lang.String username)
filePath
- 文件路径username
- 消息接收人或群idpublic void addBody(MessageBody body)
body
- 消息体public java.lang.String getFrom()
public void setFrom(java.lang.String from)
from
- public void setTo(java.lang.String to)
to
- public java.lang.String getTo()
public java.lang.String getMsgId()
public void setMsgId(java.lang.String msgId)
public void setReceipt(java.lang.String username)
public void setMessageStatusCallback(EMCallBack callBack)
callBack
- public java.lang.String toString()
toString
在类中 java.lang.Object
public void setAttribute(java.lang.String attribute, boolean value)
attribute
- 属性名value,
- 属性值public void setAttribute(java.lang.String attribute, int value)
attribute
- 属性名value,
- 属性值public void setAttribute(java.lang.String attribute, long value)
attribute
- 属性名value,
- 属性值public void setAttribute(java.lang.String attribute, JSONObject json)
attribute
- 属性名value,
- 属性值public void setAttribute(java.lang.String attribute, JSONArray json)
attribute
- 属性名value,
- 属性值public boolean getBooleanAttribute(java.lang.String attribute) throws com.easemob.exceptions.EaseMobException
attribute
- 属性名com.easemob.exceptions.EaseMobException
public boolean getBooleanAttribute(java.lang.String attribute, boolean defaultValue)
attribute
- 属性名defaultValue
- 缺省值public int getIntAttribute(java.lang.String attribute, int defaultValue)
attribute
- 属性名defaultValue
- 缺省值public long getLongAttribute(java.lang.String attribute, long defaultValue)
attribute
- 属性名defaultValue
- 缺省值public int getIntAttribute(java.lang.String attribute) throws com.easemob.exceptions.EaseMobException
attribute
- 属性名com.easemob.exceptions.EaseMobException
public long getLongAttribute(java.lang.String attribute) throws com.easemob.exceptions.EaseMobException
attribute
- 属性名com.easemob.exceptions.EaseMobException
public java.lang.String getStringAttribute(java.lang.String attribute) throws com.easemob.exceptions.EaseMobException
attribute
- 属性名com.easemob.exceptions.EaseMobException
public java.lang.String getStringAttribute(java.lang.String attribute, java.lang.String defaultValue)
attribute
- 属性名defaultValue
- 缺省值public JSONObject getJSONObjectAttribute(java.lang.String attribute) throws com.easemob.exceptions.EaseMobException
attribute
- 属性名com.easemob.exceptions.EaseMobException
public JSONArray getJSONArrayAttribute(java.lang.String attribute) throws com.easemob.exceptions.EaseMobException
attribute
- 属性名com.easemob.exceptions.EaseMobException
public EMMessage.ChatType getChatType()
public void setChatType(EMMessage.ChatType chatType)
chatType
- EMMessage.ChatType
public int describeContents()
public void writeToParcel(Parcel out, int flags)
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
在类中 java.lang.Object
java.lang.CloneNotSupportedException
public boolean isAcked()
public void setAcked(boolean isAcked)
public boolean isDelivered()
public void setDelivered(boolean isDelivered)
public boolean isUnread()
public void setUnread(boolean unread)
public void setType(EMMessage.Type type)
public boolean isListened()
public void setListened(boolean isListened)
isListened
- public java.lang.String getUserName()
public int getError()
Copyright © 2014 EaseMob.com. All Rights Reserved.