com.easemob.chat.EMChatManager Java Examples
The following examples show how to use
com.easemob.chat.EMChatManager.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatAllHistoryActivity.java From school_shop with MIT License | 6 votes |
@Override public boolean onContextItemSelected(MenuItem item) { boolean handled = false; boolean deleteMessage = false; if (item.getItemId() == R.id.delete_message) { deleteMessage = true; handled = true; } else if (item.getItemId() == R.id.delete_conversation) { deleteMessage = false; handled = true; } EMConversation tobeDeleteCons = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position); // 删除此会话 EMChatManager.getInstance().deleteConversation(tobeDeleteCons.getUserName(), tobeDeleteCons.isGroup(), deleteMessage); InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(this); inviteMessgeDao.deleteMessage(tobeDeleteCons.getUserName()); adapter.remove(tobeDeleteCons); adapter.notifyDataSetChanged(); // 更新消息未读数 // updateUnreadLabel(); return handled ? true : super.onContextItemSelected(item); }
Example #2
Source File: HXSDKHelper.java From school_shop with MIT License | 6 votes |
/** * init HuanXin listeners */ protected void initListener(){ Log.d(TAG, "init listener"); // create the global connection listener connectionListener = new EMConnectionListener() { @Override public void onDisconnected(int error) { if (error == EMError.USER_REMOVED) { onCurrentAccountRemoved(); }else if (error == EMError.CONNECTION_CONFLICT) { onConnectionConflict(); }else{ onConnectionDisconnected(error); } } @Override public void onConnected() { onConnectionConnected(); } }; //注册连接监听 EMChatManager.getInstance().addConnectionListener(connectionListener); }
Example #3
Source File: HXNotifier.java From school_shop with MIT License | 6 votes |
/** * 处理新收到的消息,然后发送通知 * * 开发者可以重载此函数 * this function can be override * * @param message */ public synchronized void onNewMsg(final EMMessage message) { if(EMChatManager.getInstance().isSlientMessage(message)){ return; } // 判断app是否在后台 if (!EasyUtils.isAppRunningForeground(appContext)) { EMLog.d(TAG, "app is running in backgroud"); sendNotification(message, false); } else { sendNotification(message, true); } viberateAndPlayTone(message); }
Example #4
Source File: HXSDKHelper.java From school_shop with MIT License | 6 votes |
/** * please make sure you have to get EMChatOptions by following method and set related options * EMChatOptions options = EMChatManager.getInstance().getChatOptions(); */ protected void initHXOptions(){ Log.d(TAG, "init HuanXin Options"); // 获取到EMChatOptions对象 EMChatOptions options = EMChatManager.getInstance().getChatOptions(); // 默认添加好友时,是不需要验证的,改成需要验证 options.setAcceptInvitationAlways(hxModel.getAcceptInvitationAlways()); // 默认环信是不维护好友关系列表的,如果app依赖环信的好友关系,把这个属性设置为true options.setUseRoster(hxModel.getUseHXRoster()); // 设置是否需要已读回执 options.setRequireAck(hxModel.getRequireReadAck()); // 设置是否需要已送达回执 options.setRequireDeliveryAck(hxModel.getRequireDeliveryAck()); // 设置从db初始化加载时, 每个conversation需要加载msg的个数 options.setNumberOfMessagesLoaded(1); notifier = createNotifier(); notifier.init(appContext); notifier.setNotificationInfoProvider(getNotificationListener()); }
Example #5
Source File: ChatActivity.java From school_shop with MIT License | 6 votes |
/** * 转发消息 * * @param forward_msg_id */ protected void forwardMessage(String forward_msg_id) { EMMessage forward_msg = EMChatManager.getInstance().getMessage(forward_msg_id); EMMessage.Type type = forward_msg.getType(); switch (type) { case TXT: // 获取消息内容,发送消息 String content = ((TextMessageBody) forward_msg.getBody()).getMessage(); sendText(content); break; case IMAGE: // 发送图片 String filePath = ((ImageMessageBody) forward_msg.getBody()).getLocalUrl(); if (filePath != null) { File file = new File(filePath); if (!file.exists()) { // 不存在大图发送缩略图 filePath = ImageUtils.getThumbnailImagePath(filePath); } sendPicture(filePath); } break; default: break; } }
Example #6
Source File: EaseChatFragment.java From monolog-android with MIT License | 6 votes |
protected void sendMessage(EMMessage message){ if(chatFragmentListener != null){ //设置扩展属性 chatFragmentListener.onSetMessageAttributes(message); } // 如果是群聊,设置chattype,默认是单聊 if (chatType == EaseConstant.CHATTYPE_GROUP){ message.setChatType(ChatType.GroupChat); }else if(chatType == EaseConstant.CHATTYPE_CHATROOM){ message.setChatType(ChatType.ChatRoom); } //发送消息 EMChatManager.getInstance().sendMessage(message, null); //刷新ui messageList.refreshSelectLast(); }
Example #7
Source File: EaseUI.java From monolog-android with MIT License | 6 votes |
protected void initChatOptions(){ Log.d(TAG, "init HuanXin Options"); // 获取到EMChatOptions对象 EMChatOptions options = EMChatManager.getInstance().getChatOptions(); // 默认添加好友时,是不需要验证的,改成需要验证 options.setAcceptInvitationAlways(false); // 默认环信是不维护好友关系列表的,如果app依赖环信的好友关系,把这个属性设置为true options.setUseRoster(false); // 设置是否需要已读回执 options.setRequireAck(false); // 设置是否需要已送达回执 options.setRequireDeliveryAck(false); // 设置从db初始化加载时, 每个conversation需要加载msg的个数 options.setNumberOfMessagesLoaded(1); notifier = createNotifier(); notifier.init(appContext); // notifier.setNotificationInfoProvider(getNotificationListener()); }
Example #8
Source File: EaseNotifier.java From monolog-android with MIT License | 6 votes |
public synchronized void onNewMesg(List<EMMessage> messages) { if(EMChatManager.getInstance().isSlientMessage(messages.get(messages.size()-1))){ return; } EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider(); if(!settingsProvider.isMsgNotifyAllowed(null)){ return; } // 判断app是否在后台 if (!EasyUtils.isAppRunningForeground(appContext)) { EMLog.d(TAG, "app is running in backgroud"); sendNotification(messages, false); } else { sendNotification(messages, true); } viberateAndPlayTone(messages.get(messages.size()-1)); }
Example #9
Source File: EaseNotifier.java From monolog-android with MIT License | 6 votes |
/** * 处理新收到的消息,然后发送通知 * * 开发者可以重载此函数 * this function can be override * * @param message */ public synchronized void onNewMsg(EMMessage message) { if(EMChatManager.getInstance().isSlientMessage(message)){ return; } EaseSettingsProvider settingsProvider = EaseUI.getInstance().getSettingsProvider(); if(!settingsProvider.isMsgNotifyAllowed(message)){ return; } // 判断app是否在后台 if (!EasyUtils.isAppRunningForeground(appContext)) { EMLog.d(TAG, "app is running in backgroud"); sendNotification(message, false); } else { sendNotification(message, true); } viberateAndPlayTone(message); }
Example #10
Source File: VideoCallActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { callHelper.onWindowResize(width, height, format); if (!cameraHelper.isStarted()) { if (!isInComingCall) { try { // 拨打视频通话 EMChatManager.getInstance().makeVideoCall(username); // 通知cameraHelper可以写入数据 cameraHelper.setStartFlag(true); } catch (EMServiceNotReadyException e) { Toast.makeText(VideoCallActivity.this, R.string.Is_not_yet_connected_to_the_server , 1).show(); } } } else { } }
Example #11
Source File: EaseChatMessageList.java From monolog-android with MIT License | 6 votes |
/** * init widget * @param toChatUsername * @param chatType * @param customChatRowProvider */ public void init(String toChatUsername, int chatType, EaseCustomChatRowProvider customChatRowProvider) { this.chatType = chatType; this.toChatUsername = toChatUsername; conversation = EMChatManager.getInstance().getConversation(toChatUsername); messageAdapter = new EaseMessageAdapter(context, toChatUsername, chatType, listView); messageAdapter.setShowAvatar(showAvatar); messageAdapter.setShowUserNick(showUserNick); messageAdapter.setMyBubbleBg(myBubbleBg); messageAdapter.setOtherBuddleBg(otherBuddleBg); messageAdapter.setCustomChatRowProvider(customChatRowProvider); // 设置adapter显示消息 listView.setAdapter(messageAdapter); refreshSelectLast(); }
Example #12
Source File: EaseChatRowImage.java From monolog-android with MIT License | 6 votes |
@Override protected void onBubbleClick() { Intent intent = new Intent(context, EaseShowBigImageActivity.class); File file = new File(imgBody.getLocalUrl()); if (file.exists()) { Uri uri = Uri.fromFile(file); intent.putExtra("uri", uri); } else { // The local full size pic does not exist yet. // ShowBigImage needs to download it from the server // first intent.putExtra("secret", imgBody.getSecret()); intent.putExtra("remotepath", imgBody.getRemoteUrl()); } if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked && message.getChatType() != ChatType.GroupChat) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); message.isAcked = true; } catch (Exception e) { e.printStackTrace(); } } context.startActivity(intent); }
Example #13
Source File: EaseChatRowFile.java From monolog-android with MIT License | 6 votes |
@Override protected void onBubbleClick() { String filePath = fileMessageBody.getLocalUrl(); File file = new File(filePath); if (file != null && file.exists()) { // 文件存在,直接打开 FileUtils.openFile(file, (Activity) context); } else { // 下载 context.startActivity(new Intent(context, EaseShowNormalFileActivity.class).putExtra("msgbody", message.getBody())); } if (message.direct == EMMessage.Direct.RECEIVE && !message.isAcked) { try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); message.isAcked = true; } catch (EaseMobException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Example #14
Source File: ChatActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@Override public void onUserRemoved(final String groupId, String groupName) { runOnUiThread(new Runnable() { public void run() { if (toChatUsername.equals(groupId)) { Toast.makeText(ChatActivity.this, "你被群创建者从此群中移除", Toast.LENGTH_SHORT).show(); EMChatManager.getInstance().deleteConversation(groupId, false); if (ChatRoomSettingActivity.instance != null) ChatRoomSettingActivity.instance.finish(); if (ChatSingleSettingActivity.instance != null) ChatSingleSettingActivity.instance.finish(); finish(); } } }); }
Example #15
Source File: ChatActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { abortBroadcast(); String msgid = intent.getStringExtra("msgid"); String from = intent.getStringExtra("from"); EMConversation conversation = EMChatManager.getInstance() .getConversation(from); if (conversation != null) { // 把message设为已读 EMMessage msg = conversation.getMessage(msgid); if (msg != null) { msg.isDelivered = true; } } adapter.notifyDataSetChanged(); }
Example #16
Source File: EaseChatRowVideo.java From monolog-android with MIT License | 6 votes |
@Override protected void onBubbleClick() { VideoMessageBody videoBody = (VideoMessageBody) message.getBody(); EMLog.d(TAG, "video view is on click"); Intent intent = new Intent(context, EaseShowVideoActivity.class); intent.putExtra("localpath", videoBody.getLocalUrl()); intent.putExtra("secret", videoBody.getSecret()); intent.putExtra("remotepath", videoBody.getRemoteUrl()); if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked && message.getChatType() != ChatType.GroupChat) { message.isAcked = true; try { EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (Exception e) { e.printStackTrace(); } } activity.startActivity(intent); }
Example #17
Source File: ChatActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { abortBroadcast(); String msgid = intent.getStringExtra("msgid"); String from = intent.getStringExtra("from"); EMConversation conversation = EMChatManager.getInstance() .getConversation(from); if (conversation != null) { // 把message设为已读 EMMessage msg = conversation.getMessage(msgid); if (msg != null) { msg.isAcked = true; } } adapter.notifyDataSetChanged(); }
Example #18
Source File: EaseMobService.java From monolog-android with MIT License | 6 votes |
/** * 全局事件监听 * 这里是拿来获取用户资料和未读计数的 */ protected void registerEaseMobEventListener() { EMChatManager.getInstance().registerEventListener(new EMEventListener() { @Override public void onEvent(EMNotifierEvent event) { final EMMessage msg = (EMMessage) event.getData(); if (event.getEvent() == EMNotifierEvent.Event.EventNewMessage) { //未在聊天的任何界面就计数 if (!EaseUI.getInstance().hasForegroundActivies()) { PrefService.getInstance(mContext).increatUnread(); Log.d(TAG, "new Msg Count"); } //更新联系人 asyncContact(msg); //广播通知,主界面拿来更新的 Intent broadcastIntent = new Intent(MsgReceiver.NEW_MSG_BROADCAST); mContext.sendBroadcast(broadcastIntent, null); } } }); }
Example #19
Source File: EaseMobService.java From monolog-android with MIT License | 6 votes |
/** * 用户登录 * * @param handler */ public void easeMobLogin(final Handler handler) { UserBean user = AppContext.getInstance().getUser(); String name = user.getId(); String pwd = "pwd" + user.getId(); EMChatManager.getInstance().login(name, pwd, new EMCallBack() { @Override public void onSuccess() { handler.sendEmptyMessage(0); } @Override public void onProgress(int progress, String status) { } @Override public void onError(final int code, final String error) { handler.sendEmptyMessage(1); } }); }
Example #20
Source File: HXSDKHelper.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
/** * please make sure you have to get EMChatOptions by following method and set related options * EMChatOptions options = EMChatManager.getInstance().getChatOptions(); */ protected void initHXOptions(){ Log.d(TAG, "init HuanXin Options"); // 获取到EMChatOptions对象 EMChatOptions options = EMChatManager.getInstance().getChatOptions(); // 默认添加好友时,是不需要验证的,改成需要验证 options.setAcceptInvitationAlways(hxModel.getAcceptInvitationAlways()); // 默认环信是不维护好友关系列表的,如果app依赖环信的好友关系,把这个属性设置为true options.setUseRoster(hxModel.getUseHXRoster()); // 设置收到消息是否有新消息通知(声音和震动提示),默认为true options.setNotifyBySoundAndVibrate(hxModel.getSettingMsgNotification()); // 设置收到消息是否有声音提示,默认为true options.setNoticeBySound(hxModel.getSettingMsgSound()); // 设置收到消息是否震动 默认为true options.setNoticedByVibrate(hxModel.getSettingMsgVibrate()); // 设置语音消息播放是否设置为扬声器播放 默认为true options.setUseSpeaker(hxModel.getSettingMsgSpeaker()); // 设置是否需要已读回执 options.setRequireAck(hxModel.getRequireReadAck()); // 设置是否需要已送达回执 options.setRequireDeliveryAck(hxModel.getRequireDeliveryAck()); // 设置notification消息点击时,跳转的intent为自定义的intent options.setOnNotificationClickListener(getNotificationClickListener()); options.setNotifyText(getMessageNotifyListener()); }
Example #21
Source File: HXSDKHelper.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 6 votes |
/** * init HuanXin listeners */ protected void initListener(){ Log.d(TAG, "init listener"); // create the global connection listener connectionListener = new EMConnectionListener() { @Override public void onDisconnected(int error) { if (error == EMError.USER_REMOVED) { onCurrentAccountRemoved(); }else if (error == EMError.CONNECTION_CONFLICT) { onConnectionConflict(); }else{ onConnectionDisconnected(error); } } @Override public void onConnected() { onConnectionConnected(); } }; EMChatManager.getInstance().addConnectionListener(connectionListener); }
Example #22
Source File: MessageAdapter.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * 发送消息 * * @param message * @param holder * @param position */ public void sendMsgInBackground(final EMMessage message, final ViewHolder holder) { holder.staus_iv.setVisibility(View.GONE); holder.pb.setVisibility(View.VISIBLE); final long start = System.currentTimeMillis(); // 调用sdk发送异步发送方法 EMChatManager.getInstance().sendMessage(message, new EMCallBack() { @Override public void onSuccess() { // umeng自定义事件, updateSendedView(message, holder); } @Override public void onError(int code, String error) { updateSendedView(message, holder); } @Override public void onProgress(int progress, String status) { } }); }
Example #23
Source File: MessageAdapter.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
public MessageAdapter(Context context, String username, int chatType) { this.username = username; this.context = context; inflater = LayoutInflater.from(context); activity = (Activity) context; this.conversation = EMChatManager.getInstance().getConversation( username); avatarLoader = new LoadUserAvatar(context, "/sdcard/fanxin/"); }
Example #24
Source File: DemoHXSDKHelper.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
@Override protected void initListener() { super.initListener(); IntentFilter callFilter = new IntentFilter(EMChatManager.getInstance() .getIncomingVoiceCallBroadcastAction()); appContext.registerReceiver(new VoiceCallReceiver(), callFilter); }
Example #25
Source File: ChatActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
/** * 转发消息 * * @param forward_msg_id */ protected void forwardMessage(String forward_msg_id) { EMMessage forward_msg = EMChatManager.getInstance().getMessage( forward_msg_id); EMMessage.Type type = forward_msg.getType(); switch (type) { case TXT: // 获取消息内容,发送消息 String content = ((TextMessageBody) forward_msg.getBody()) .getMessage(); sendText(content); break; case IMAGE: // 发送图片 String filePath = ((ImageMessageBody) forward_msg.getBody()) .getLocalUrl(); if (filePath != null) { File file = new File(filePath); if (!file.exists()) { // 不存在大图发送缩略图 filePath = ImageUtils.getThumbnailImagePath(filePath); } sendPicture(filePath, false); } break; default: break; } }
Example #26
Source File: ChatAllHistoryActivity.java From school_shop with MIT License | 5 votes |
/** * 获取所有会话 * * @param context * @return + */ private List<EMConversation> loadConversationsWithRecentChat() { // 获取所有会话,包括陌生人 Hashtable<String, EMConversation> conversations = EMChatManager.getInstance().getAllConversations(); // 过滤掉messages size为0的conversation /** * 如果在排序过程中有新消息收到,lastMsgTime会发生变化 * 影响排序过程,Collection.sort会产生异常 * 保证Conversation在Sort过程中最后一条消息的时间不变 * 避免并发问题 */ List<Pair<Long, EMConversation>> sortList = new ArrayList<Pair<Long, EMConversation>>(); synchronized (conversations) { for (EMConversation conversation : conversations.values()) { if (conversation.getAllMessages().size() != 0) { sortList.add(new Pair<Long, EMConversation>(conversation.getLastMessage().getMsgTime(), conversation)); } } } try { // Internal is TimSort algorithm, has bug sortConversationByLastChatTime(sortList); } catch (Exception e) { e.printStackTrace(); } List<EMConversation> list = new ArrayList<EMConversation>(); for (Pair<Long, EMConversation> sortItem : sortList) { list.add(sortItem.second); } return list; }
Example #27
Source File: MessageAdapter.java From school_shop with MIT License | 5 votes |
public MessageAdapter(Context context, String username, int chatType) { this.username = username; this.context = context; inflater = LayoutInflater.from(context); activity = (Activity) context; this.conversation = EMChatManager.getInstance().getConversation(username); }
Example #28
Source File: MessageAdapter.java From school_shop with MIT License | 5 votes |
/** * 显示用户头像 * @param message * @param imageView */ private void setUserAvatar(EMMessage message, ImageView imageView){ if(message.direct == Direct.SEND){ //显示自己头像 UserUtils.setUserAvatar(context, EMChatManager.getInstance().getCurrentUser(), imageView); }else{ UserUtils.setUserAvatar(context, message.getFrom(), imageView,ChatActivity.buserAvatar); } }
Example #29
Source File: VideoCallActivity.java From FanXin-based-HuanXin with GNU General Public License v2.0 | 5 votes |
@Override public void onBackPressed() { EMChatManager.getInstance().endCall(); callDruationText = chronometer.getText().toString(); saveCallRecord(1); finish(); }
Example #30
Source File: MessageAdapter.java From school_shop with MIT License | 5 votes |
/** * 发送消息 * * @param message * @param holder * @param position */ public void sendMsgInBackground(final EMMessage message, final ViewHolder holder) { holder.staus_iv.setVisibility(View.GONE); holder.pb.setVisibility(View.VISIBLE); final long start = System.currentTimeMillis(); // 调用sdk发送异步发送方法 EMChatManager.getInstance().sendMessage(message, new EMCallBack() { @Override public void onSuccess() { updateSendedView(message, holder); } @Override public void onError(int code, String error) { updateSendedView(message, holder); } @Override public void onProgress(int progress, String status) { } }); }