注册

急!!我把聊天记录存储到本地服务器后,客服端从本地服务器获取聊天记录,可是图片显示不了,该怎么办



PLG5IU{OXP@S)ZF5]NM7Q73.png


这是我的代码
JSONObject object = new JSONObject(response);
int ret_code = object.optInt("ret_code");
String ret_msg = object.optString("ret_msg");
if (ret_code == 0) {
JSONObject messagesRecord = object.optJSONObject("messagesRecord");
JSONArray jsonArray = messagesRecord.optJSONArray("entities");

for (int i = jsonArray.length()-1; i >= 0; i--) {
EMMessage msg = null;
JSONObject entities = jsonArray.optJSONObject(i);
JSONObject payload = entities.optJSONObject("payload");
JSONArray bodies = payload.optJSONArray("bodies");

String to = entities.optString("to");//接收人的username或者接收group的ID
String from = entities.optString("from");//发送人username
String msgId = entities.optString("msg_id");
String ct = entities.optString("chat_type");
long timestamp = entities.optLong("timestamp");

ChatType eType = ChatType.Chat;
if (ct.equals(ChatType.ChatRoom.toString().toLowerCase()))
eType = ChatType.ChatRoom;
else if (ct.equals(ChatType.GroupChat.toString().toLowerCase()))
eType = ChatType.GroupChat;

// // 获取用户username或者群组groupid
String username = conversation.getUserName();
EaseUser user = UserUtils.getUserInfo(username);
String userId = user!=null?user.getUserId():"";
//判断消息是不是用户自己发送的
EMMessage.Direct direct = from.equals(userId)?EMMessage.Direct.SEND:EMMessage.Direct.RECEIVE;

if (bodies.length() > 0) {
JSONObject o = bodies.optJSONObject(0);
String type = o.optString("type");

if (type.equals("txt")) {
msg = EMMessage.createSendMessage(EMMessage.Type.TXT);
TextMessageBody body = new TextMessageBody(o.optString("msg"));
msg.addBody(body);
} else if (type.equals("img")) {

String thumbRemoteUrl = o.optString("thumb");
msg = EMMessage.createSendMessage(EMMessage.Type.IMAGE);
ImageMessageBody body = new ImageMessageBody();
body.setRemoteUrl(o.optString("url"));
body.setLocalUrl(EaseImageUtils.getThumbnailImagePath(thumbRemoteUrl));
body.setFileName(o.optString("filename"));
body.setThumbnailUrl(thumbRemoteUrl);
body.setThumbnailSecret(o.optString("thumb_secret"));
body.setSecret(o.optString("secret"));
body.downloaded = true;
msg.addBody(body);

} else if (type.equals("loc")) {
msg = EMMessage.createSendMessage(EMMessage.Type.LOCATION);
LocationMessageBody body = new LocationMessageBody(o.optString("addr")
, o.optDouble("lat"), o.optDouble("lng"));
msg.addBody(body);

}

msg.setMsgId(msgId);
msg.setFrom(from);
msg.setTo(to);
msg.setChatType(eType);
msg.setMsgTime(timestamp);
msg.setUnread(true);
msg.direct = direct;
msg.status = EMMessage.Status.SUCCESS;
conversation.addMessage(msg);
}
}
} else {
Log.e(TAG, ret_msg);
}

 
 
这是我把从本地服务器获取的图片消息转换成EMMessage类对象的属性
attributes = {Hashtable@830059225400}  size = 0
 body = {ImageMessageBody@830059225808} "image:IMG_20160628_173947.jpg,localurl:http://182.92.228.160:80/furuiweifei/barapp/chatfiles/9260e250-48cc-11e6-af22-377340d7ffb6,remoteurl:http://182.92.228.160:80/furuiweifei/barapp/chatfiles/9260e250-48cc-11e6-af22-377340d7ffb6,thumbnial:http://182.92.228.160:80/furuiweifei/barapp/chatfiles/9260e250-48cc-11e6-af22-377340d7ffb6"
  thumbnailUrl = "http://182.92.228.160:80/furuiweifei/barapp/chatfiles/9260e250-48cc-11e6-af22-377340d7ffb6"
  thumbnailSecret = ""
  sendOriginalImage = false
  height = 0
  width = 0
  downloadCallback = null
  secret = "kmDiWkjMEea-jHsmOpyqvB6eey2jf7Eqm7FqL2lgwsi0qhtv"
  fileName = "IMG_20160628_173947.jpg"
  localUrl = "http://182.92.228.160:80/furuiweifei/barapp/chatfiles/9260e250-48cc-11e6-af22-377340d7ffb6"
  remoteUrl = "http://182.92.228.160:80/furuiweifei/barapp/chatfiles/9260e250-48cc-11e6-af22-377340d7ffb6"
  downloaded = false
 chatType = {EMMessage$ChatType@830055958208} "GroupChat"
 direct = {EMMessage$Direct@830055982264} "RECEIVE"
 type = {EMMessage$Type@830055982904} "IMAGE"
 from = {EMContact@830059286720} ""
 to = {EMContact@830059286744} ""
 status = {EMMessage$Status@830055984360} "SUCCESS"
 msgId = "218315828607582780"
 messageStatusCallBack = null
 msgTime = 1468395414908
 isListened = false
 offline = false
 progress = 0
 isDelivered = false
 isAcked = false
 error = 0
 unread = true
已邀请:
如果是自己做的ui界面的话,图片你要根据消息体里面的图片远程地址去下载下来。

要回复问题请先登录注册