Beispiel #1
0
 /**
  * 消息重发
  *
  * @param msg
  * @return
  */
 public static long reSendECMessage(ECMessage msg) {
   ECChatManager manager = getInstance().mChatManager;
   if (manager != null) {
     // 调用接口发送IM消息
     String oldMsgId = msg.getMsgId();
     manager.sendMessage(msg, getInstance().mListener);
     if (msg.getType() == ECMessage.Type.IMAGE) {
       ImgInfo imgInfo = ImgInfoSqlManager.getInstance().getImgInfo(oldMsgId);
       if (imgInfo == null || TextUtils.isEmpty(imgInfo.getBigImgPath())) {
         return -1;
       }
       String bigImagePath =
           new File(FileAccessor.getImagePathName(), imgInfo.getBigImgPath()).getAbsolutePath();
       imgInfo.setMsglocalid(msg.getMsgId());
       ECFileMessageBody body = (ECFileMessageBody) msg.getBody();
       body.setLocalUrl(bigImagePath);
       BitmapFactory.Options options =
           DemoUtils.getBitmapOptions(
               new File(FileAccessor.IMESSAGE_IMAGE, imgInfo.getThumbImgPath()).getAbsolutePath());
       msg.setUserData(
           "outWidth://"
               + options.outWidth
               + ",outHeight://"
               + options.outHeight
               + ",THUMBNAIL://"
               + msg.getMsgId());
       ImgInfoSqlManager.getInstance().updateImageInfo(imgInfo);
     }
     // 保存发送的消息到数据库
     return IMessageSqlManager.changeResendMsg(msg.getId(), msg);
   }
   return -1;
 }
Beispiel #2
0
  public static long sendImageMessage(ImgInfo imgInfo, ECMessage message) {

    ECChatManager manager = getInstance().mChatManager;
    if (manager != null) {
      // 调用接口发送IM消息
      manager.sendMessage(message, getInstance().mListener);

      if (TextUtils.isEmpty(message.getMsgId())) {
        return -1;
      }
      imgInfo.setMsglocalid(message.getMsgId());
      BitmapFactory.Options options =
          DemoUtils.getBitmapOptions(
              new File(FileAccessor.IMESSAGE_IMAGE, imgInfo.getThumbImgPath()).getAbsolutePath());
      message.setUserData(
          "outWidth://"
              + options.outWidth
              + ",outHeight://"
              + options.outHeight
              + ",THUMBNAIL://"
              + message.getMsgId()
              + ",PICGIF://"
              + imgInfo.isGif);
      long row = IMessageSqlManager.insertIMessage(message, ECMessage.Direction.SEND.ordinal());
      if (row != -1) {
        return ImgInfoSqlManager.getInstance().insertImageInfo(imgInfo);
      }
    }
    return -1;
  }
Beispiel #3
0
 /**
  * 发送ECMessage 消息
  *
  * @param msg
  */
 public static long sendECMessage(ECMessage msg) {
   getInstance().checkChatManager();
   // 获取一个聊天管理器
   ECChatManager manager = getInstance().mChatManager;
   if (manager != null) {
     // 调用接口发送IM消息
     msg.setMsgTime(System.currentTimeMillis());
     manager.sendMessage(msg, getInstance().mListener);
     // 保存发送的消息到数据库
   } else {
     msg.setMsgStatus(ECMessage.MessageStatus.FAILED);
   }
   return IMessageSqlManager.insertIMessage(msg, ECMessage.Direction.SEND.ordinal());
 }
Beispiel #4
0
  public void sendMessage(final Friend friend, History history) {
    try {
      ECMessage msg = ECMessage.createECMessage(ECMessage.Type.TXT);
      msg.setForm(UserCache.getInstance().getClientUser().getUserId() + "");
      msg.setMsgTime(System.currentTimeMillis());

      msg.setTo(friend.getUserId() + "");
      msg.setSessionId(friend.getUserId() + "");
      msg.setDirection(ECMessage.Direction.SEND);

      String content =
          history.getScene().getSceneId() + "/" + history.getTime() + "/" + history.getStatus();
      ECTextMessageBody msgBody = new ECTextMessageBody(content);
      LogUtil.d(TAG, "The content is " + content);
      msg.setBody(msgBody);
      ECChatManager manager = ECDevice.getECChatManager();
      manager.sendMessage(msg, mOnSendMessageListener);
    } catch (Exception e) {
      LogUtil.e(TAG, "send message fail , e=" + e.getMessage());
    }
  }