hyphenate_SDK3.0  3.8.5
hyphenatejavaIMSDK
| Public 成员函数 | 静态 Public 成员函数 | 静态 Public 属性 | 所有成员列表
com.hyphenate.chat.EMMessage类 参考
类 com.hyphenate.chat.EMMessage 继承关系图:

enum  ChatType
 
enum  Direct
 
class  EMCallbackHolder
 
enum  Status
 
enum  Type
 

Public 成员函数

Status status ()
 
 EMMessage (EMAMessage message)
 
void setStatus (Status status)
 
Type getType ()
 
EMMessageBody 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 (EMMessageBody body)
 
void addBody (EMMessageBody body)
 
String getFrom ()
 
void setFrom (String from)
 
void setTo (String to)
 
String getTo ()
 
String getMsgId ()
 
void setMsgId (String msgId)
 
synchronized void setMessageStatusCallback (EMCallBack 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 HyphenateException
 
boolean getBooleanAttribute (String attribute, boolean defaultValue)
 
int getIntAttribute (String attribute, int defaultValue)
 
long getLongAttribute (String attribute, long defaultValue)
 
int getIntAttribute (String attribute) throws HyphenateException
 
long getLongAttribute (String attribute) throws HyphenateException
 
String getStringAttribute (String attribute) throws HyphenateException
 
String getStringAttribute (String attribute, String defaultValue)
 
JSONObject getJSONObjectAttribute (String attribute) throws HyphenateException
 
JSONArray getJSONArrayAttribute (String attribute) throws HyphenateException
 
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 ()
 

静态 Public 成员函数

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

静态 Public 属性

static final Parcelable.Creator< EMMessageCREATOR
 

详细描述

消息对象,代表一条发送或接收到的消息

构造一条文本发送消息

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

构造一条图片消息

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

成员函数说明

void com.hyphenate.chat.EMMessage.addBody ( EMMessageBody  body)

添加消息体 现在只支持添加一个消息体

参数
body消息体
String com.hyphenate.chat.EMMessage.conversationId ( )

获取会话id

返回
会话id
static EMMessage com.hyphenate.chat.EMMessage.createFileSendMessage ( String  filePath,
String  username 
)
static

创建一个普通文件发送消息

参数
filePath文件路径
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createFileSendMessage ( Uri  filePath,
String  username 
)
static

创建一个普通文件发送消息

参数
filePath文件路径
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createImageSendMessage ( String  filePath,
boolean  sendOriginalImage,
String  username 
)
static

创建一个图片发送消息

参数
filePath图片路径
sendOriginalImage是否发送原图(默认大于100K的图片sdk会进行压缩)
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createImageSendMessage ( Uri  imgUri,
boolean  sendOriginalImage,
String  username 
)
static

创建一个图片发送消息

参数
imgUri图片Uri
sendOriginalImage是否发送原图(默认大于100K的图片sdk会进行压缩)
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createLocationSendMessage ( double  latitude,
double  longitude,
String  locationAddress,
String  username 
)
static

创建一个位置发送消息

参数
latitude纬度
longitude经度
locationAddress位置详情
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createReceiveMessage ( Type  type)
static

创建一个接收消息

参数
type消息类型
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createSendMessage ( Type  type)
static

创建一个发送消息

参数
type消息类型
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createTxtSendMessage ( String  content,
String  username 
)
static

创建一个文本发送消息

参数
content文本内容
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createVideoSendMessage ( String  videofilePath,
String  imageThumbPath,
int  timeLength,
String  username 
)
static

创建一个视频发送消息

参数
videofilePath视频文件路径
imageThumbPath视频第一帧图缩略图
timeLength视频时间长度(单位秒)
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createVideoSendMessage ( Uri  videofilePath,
String  imageThumbPath,
int  timeLength,
String  username 
)
static

创建一个视频发送消息

参数
videofilePath视频文件路径
imageThumbPath视频第一帧图缩略图
timeLength视频时间长度(单位秒)
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createVideoSendMessage ( Uri  videofilePath,
Uri  imageThumbPath,
int  timeLength,
String  username 
)
static

创建一个视频发送消息

参数
videofilePath视频文件路径
imageThumbPath视频第一帧图缩略图
timeLength视频时间长度(单位秒)
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createVoiceSendMessage ( String  filePath,
int  timeLength,
String  username 
)
static

创建一个语音发送消息

参数
filePath语音文件路径
timeLength语音时间长度(单位秒)
username消息接收人或群id
返回
消息对象
static EMMessage com.hyphenate.chat.EMMessage.createVoiceSendMessage ( Uri  filePath,
int  timeLength,
String  username 
)
static

创建一个语音发送消息

参数
filePath语音文件uri
timeLength语音时间长度(单位秒)
username消息接收人或群id
返回
消息对象
Direct com.hyphenate.chat.EMMessage.direct ( )

消息方向

返回
详见 Direct
Map<String, Object> com.hyphenate.chat.EMMessage.ext ( )

获取消息包含的全部扩展字段,并以Map形式返回

返回
消息的扩展字段,以Map形式返回,返回Entry.value的具体类型有Boolean, Integer, Long, Float, Double, String 输入JsonObject的属性,map结构返回时属性是String
EMMessageBody com.hyphenate.chat.EMMessage.getBody ( )

获取消息体

返回
消息体
boolean com.hyphenate.chat.EMMessage.getBooleanAttribute ( String  attribute) throws HyphenateException

获取boolean 类型扩展属性

参数
attribute属性名
返回
属性值
异常
HyphenateException
boolean com.hyphenate.chat.EMMessage.getBooleanAttribute ( String  attribute,
boolean  defaultValue 
)

获取 boolean 类型扩展属性

参数
attribute属性名
defaultValue缺省值
返回
属性值
ChatType com.hyphenate.chat.EMMessage.getChatType ( )

获取聊天类型

返回
ChatType
String com.hyphenate.chat.EMMessage.getFrom ( )

获取消息发送者的用户名

返回
用户名
int com.hyphenate.chat.EMMessage.getIntAttribute ( String  attribute,
int  defaultValue 
)

获取 int 类型扩展属性

参数
attribute属性名
defaultValue缺省值
返回
属性值
int com.hyphenate.chat.EMMessage.getIntAttribute ( String  attribute) throws HyphenateException

获取 int 类型扩展属性

参数
attribute属性名
返回
属性值
异常
HyphenateException
JSONArray com.hyphenate.chat.EMMessage.getJSONArrayAttribute ( String  attribute) throws HyphenateException

获取 JSONArray 类型扩展属性

参数
attribute属性名
返回
属性值
异常
HyphenateException
JSONObject com.hyphenate.chat.EMMessage.getJSONObjectAttribute ( String  attribute) throws HyphenateException

获取 JSONObject 类型扩展属性

参数
attribute属性名
返回
属性值
异常
HyphenateException
long com.hyphenate.chat.EMMessage.getLongAttribute ( String  attribute,
long  defaultValue 
)

获取 long 类型扩展属性

参数
attribute属性名
defaultValue缺省值
返回
属性值
long com.hyphenate.chat.EMMessage.getLongAttribute ( String  attribute) throws HyphenateException

获取 long 类型扩展属性

参数
attribute属性名
返回
属性值
异常
HyphenateException
String com.hyphenate.chat.EMMessage.getMsgId ( )

获取消息的id

返回
消息的id
long com.hyphenate.chat.EMMessage.getMsgTime ( )

获取消息的时间戳(服务器时间)

返回
消息的时间戳(服务器时间)
String com.hyphenate.chat.EMMessage.getStringAttribute ( String  attribute) throws HyphenateException

获取 String 类型扩展属性

参数
attribute属性名
返回
属性值
异常
HyphenateException
String com.hyphenate.chat.EMMessage.getStringAttribute ( String  attribute,
String  defaultValue 
)

获取 String 类型扩展属性

参数
attribute属性名
defaultValue缺省值
返回
属性值
String com.hyphenate.chat.EMMessage.getTo ( )

获取消息接收者的用户名

返回
接收者的用户名
Type com.hyphenate.chat.EMMessage.getType ( )

获取消息类型

返回
消息类型
String com.hyphenate.chat.EMMessage.getUserName ( )

获取通话对象

返回
对方id
int com.hyphenate.chat.EMMessage.groupAckCount ( )

群消息被读的人数

返回
消息被读的人数
boolean com.hyphenate.chat.EMMessage.isAcked ( )

对方是否已读

返回
是否已读
boolean com.hyphenate.chat.EMMessage.isDelivered ( )

获取消息是否已到达对方

返回
消息是否已到达对方
boolean com.hyphenate.chat.EMMessage.isListened ( )

获取语音是否已听

返回
boolean com.hyphenate.chat.EMMessage.isNeedGroupAck ( )

消息是否需要群组已读回执

返回
true:需要已读回执;false:不需要已读回执
boolean com.hyphenate.chat.EMMessage.isUnread ( )

检查消息是否已读

返回
消息是否已读
long com.hyphenate.chat.EMMessage.localTime ( )

获取消息的本地时间戳

返回
消息的本地时间戳
int com.hyphenate.chat.EMMessage.progress ( )

消息包含附件的上传或者下载进度,值的范围0-100 消息附件的缩略图不涉及进度信息

返回
进度值
void com.hyphenate.chat.EMMessage.setAcked ( boolean  isAcked)

设置对方是否已读 开发者不应该调用此方法,由SDK进行调用

参数
isAcked
void com.hyphenate.chat.EMMessage.setAttribute ( String  attribute,
boolean  value 
)

设置消息的boolean 类型扩展属性

参数
attribute属性名
value属性值
void com.hyphenate.chat.EMMessage.setAttribute ( String  attribute,
int  value 
)

设置消息的int 类型扩展属性

参数
attribute属性名
value属性值
void com.hyphenate.chat.EMMessage.setAttribute ( String  attribute,
long  value 
)

设置消息的long 类型扩展属性

参数
attribute属性名
value属性值
void com.hyphenate.chat.EMMessage.setAttribute ( String  attribute,
JSONObject  value 
)

设置消息的JSONObject 类型扩展属性

参数
attribute属性名
value属性值
void com.hyphenate.chat.EMMessage.setAttribute ( String  attribute,
JSONArray  value 
)

设置消息的JSONArray 类型扩展属性

参数
attribute属性名
value属性值
void com.hyphenate.chat.EMMessage.setAttribute ( String  attribute,
String  value 
)

设置消息的string 类型扩展属性

参数
attribute属性名
value属性值
void com.hyphenate.chat.EMMessage.setBody ( EMMessageBody  body)

设置消息体

参数
body
void com.hyphenate.chat.EMMessage.setChatType ( ChatType  chatType)

设置聊天类型 缺省为单聊ChatType#Chat

参数
chatType聊天类型,详见ChatType
void com.hyphenate.chat.EMMessage.setDeliverAcked ( boolean  isDeliverAcked)

设置消息已送达标记 开发者不要调用,由SDK内部调用

参数
isDeliverAcked
void com.hyphenate.chat.EMMessage.setDelivered ( boolean  isDelivered)

设置消息是否已经送达对方 开发者不要调用,由SDK内部调用

参数
isDelivered
void com.hyphenate.chat.EMMessage.setDirection ( Direct  dir)

设置消息的方向

参数
dir消息的方向,详见Direct
void com.hyphenate.chat.EMMessage.setFrom ( String  from)

设置消息发送者id

参数
from发送者id
void com.hyphenate.chat.EMMessage.setGroupAckCount ( int  count)

设置群消息被读的人数

参数
count
void com.hyphenate.chat.EMMessage.setIsNeedGroupAck ( boolean  need)

设置消息是否需要群组已读回执

参数
need
void com.hyphenate.chat.EMMessage.setListened ( boolean  isListened)

设置语音是否已听

参数
isListened
void com.hyphenate.chat.EMMessage.setLocalTime ( long  serverTime)

设置消息的本地时间戳

参数
serverTime消息的本地时间戳
synchronized void com.hyphenate.chat.EMMessage.setMessageStatusCallback ( EMCallBack  callback)

设置消息状态改变的回调 设置消息状态回调,以便刷新界面

参数
callback消息状态改变的回调
void com.hyphenate.chat.EMMessage.setMsgId ( String  msgId)

设置本地消息id

参数
msgId消息id
void com.hyphenate.chat.EMMessage.setMsgTime ( long  msgTime)

设置消息的时间戳(服务器时间)

参数
msgTime消息的时间戳(服务器时间)
void com.hyphenate.chat.EMMessage.setProgress ( int  progress)

设置消息包含附件的上传或者下载进度,值的范围0-100 对于app开发者来说,通常不需要主动设置进度

参数
progress
void com.hyphenate.chat.EMMessage.setStatus ( Status  status)

设置消息的状态

参数
status息的状态
void com.hyphenate.chat.EMMessage.setTo ( String  to)

设置消息的接收者id

参数
to收者id
void com.hyphenate.chat.EMMessage.setUnread ( boolean  unread)

设置消息已读 建议在会话中,使用EMConversation#markAllMessagesAsRead()

参数
unread

设置消息已读 It is recommended to use EMConversation#markAllMessagesAsRead() in a conversation

参数
unread
Status com.hyphenate.chat.EMMessage.status ( )

获取消息的发送/接收状态

返回
消息的发送/接收状态

类成员变量说明

final Parcelable.Creator<EMMessage> com.hyphenate.chat.EMMessage.CREATOR
static
初始值:
= new Parcelable.Creator<EMMessage>() {
public EMMessage createFromParcel(Parcel in) {
EMMessage msg = null;
try {
msg = new EMMessage(in);
} catch (HyphenateException e) {
e.printStackTrace();
}
return msg;
}
public EMMessage[] newArray(int size) {
return new EMMessage[size];
}
}

该类的文档由以下文件生成: