Пример #1
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());
 }
Пример #2
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());
    }
  }