当前位置: 首页>>代码示例>>Java>>正文


Java EMChatManager类代码示例

本文整理汇总了Java中com.easemob.chat.EMChatManager的典型用法代码示例。如果您正苦于以下问题:Java EMChatManager类的具体用法?Java EMChatManager怎么用?Java EMChatManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EMChatManager类属于com.easemob.chat包,在下文中一共展示了EMChatManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMsgInBackground

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
/**
 * 发送消息
 * 
 * @param message
 * @param holder
 */
public void sendMsgInBackground(final EMMessage message, final ViewHolder holder) {
	holder.staus_iv.setVisibility(View.GONE);
	holder.pb.setVisibility(View.VISIBLE);
	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) {
		}

	});

}
 
开发者ID:macyuan,项目名称:TAG,代码行数:29,代码来源:MessageAdapter.java

示例2: forwardMessage

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
/**
 * 转发消息
 * 
 * @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;
	}
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:31,代码来源:ChatActivity.java

示例3: onReceive

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
	String username = intent.getStringExtra("from");
	String msgid = intent.getStringExtra("msgid");
	// 收到这个广播的时候,message已经在db和内存里了,可以通过id获取mesage对象
	EMMessage message = EMChatManager.getInstance().getMessage(msgid);
	// 如果是群聊消息,获取到group id
	if (message.getChatType() == ChatType.GroupChat) {
		username = message.getTo();
	}
	if (!username.equals(toChatUsername)) {
		// 消息不是发给当前会话,return
		return;
	}
				// conversation =
	// EMChatManager.getInstance().getConversation(toChatUsername);
	// 通知adapter有新消息,更新ui
	adapter.refresh();
	listView.setSelection(listView.getCount() - 1);
	// 记得把广播给终结掉
	abortBroadcast();
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:23,代码来源:ChatActivity.java

示例4: onApplicationAccept

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@Override
public void onApplicationAccept(String groupId, String groupName, String accepter) {
	//加群申请被同意
	EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
	msg.setChatType(ChatType.GroupChat);
	msg.setFrom(accepter);
	msg.setTo(groupId);
	msg.setMsgId(UUID.randomUUID().toString());
	msg.addBody(new TextMessageBody(accepter + "同意了你的群聊申请"));
	// 保存同意消息
	EMChatManager.getInstance().saveMessage(msg);
	// 提醒新消息
	EMNotifier.getInstance(getApplicationContext()).notifyOnNewMsg();

	runOnUiThread(new Runnable() {
		public void run() {
			updateUnreadLabel();
			// 刷新ui
			if (currentTabIndex == CHATHISTORYFRAGMENT)
				chatHistoryFragment.refresh();
			if (CommonUtils.getTopActivity(MainActivity_0903.this).equals(GroupsActivity.class.getName())) {
				GroupsActivity.instance.onResume();
			}
		}
	});
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:27,代码来源:MainActivity_0903.java

示例5: onApplicationAccept

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@Override
public void onApplicationAccept(String groupId, String groupName, String accepter) {
	//加群申请被同意
	EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
	msg.setChatType(ChatType.GroupChat);
	msg.setFrom(accepter);
	msg.setTo(groupId);
	msg.setMsgId(UUID.randomUUID().toString());
	msg.addBody(new TextMessageBody(accepter + "同意了你的群聊申请"));
	// 保存同意消息
	EMChatManager.getInstance().saveMessage(msg);
	// 提醒新消息
	EMNotifier.getInstance(getApplicationContext()).notifyOnNewMsg();

	runOnUiThread(new Runnable() {
		public void run() {
			updateUnreadLabel();
			// 刷新ui
			if (currentTabIndex == CHATHISTORYFRAGMENT)
				chatHistoryFragment.refresh();
			if (CommonUtils.getTopActivity(MainActivity.this).equals(GroupsActivity.class.getName())) {
				GroupsActivity.instance.onResume();
			}
		}
	});
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:27,代码来源:MainActivity.java

示例6: onResume

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@Override
protected void onResume() {
	super.onResume();
	if (!isConflict) {
		try {//增加 try 模块
			updateUnreadLabel();
			updateUnreadAddressLable();
			EMChatManager.getInstance().activityResumed();

		} catch (Exception e) {
			// TODO: handle exception
		}

	}

}
 
开发者ID:macyuan,项目名称:TAG,代码行数:17,代码来源:MainActivity.java

示例7: onContextItemSelected

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@Override
public boolean onContextItemSelected(MenuItem item) {
	if (item.getItemId() == R.id.delete_message) {
		EMConversation tobeDeleteCons = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
		// 删除此会话
		EMChatManager.getInstance().deleteConversation(tobeDeleteCons.getUserName(),tobeDeleteCons.isGroup());
		InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(getActivity());
		inviteMessgeDao.deleteMessage(tobeDeleteCons.getUserName());
		adapter.remove(tobeDeleteCons);
		adapter.notifyDataSetChanged();

		// 更新消息未读数
		((MainActivity) getActivity()).updateUnreadLabel();

		return true;
	}
	return super.onContextItemSelected(item);
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:19,代码来源:ChatAllHistoryFragment.java

示例8: onContextItemSelected

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.delete_message) {
        EMConversation tobeDeleteCons = adapter.getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position);
        // 删除此会话
        EMChatManager.getInstance().deleteConversation(tobeDeleteCons.getUserName(), tobeDeleteCons.isGroup());
        InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(mContext);
        inviteMessgeDao.deleteMessage(tobeDeleteCons.getUserName());
        adapter.remove(tobeDeleteCons);
        adapter.notifyDataSetChanged();

        // 更新消息未读数
        // ((MainActivity) getActivity()).updateUnreadLabel();
        return true;
    }
    return super.onContextItemSelected(item);
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:18,代码来源:ChatAllHistoryActivity.java

示例9: onContextItemSelected

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@Override
public boolean onContextItemSelected(MenuItem item) {
	if (item.getItemId() == R.id.delete_message) {
		EMContact tobeDeleteUser = adapter.getItem(((AdapterContextMenuInfo) item.getMenuInfo()).position);
		boolean isGroup = false;
		if(tobeDeleteUser instanceof EMGroup)
			isGroup = true;
		// 删除此会话
		EMChatManager.getInstance().deleteConversation(tobeDeleteUser.getUsername(),isGroup);
		InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(getActivity());
		inviteMessgeDao.deleteMessage(tobeDeleteUser.getUsername());
		adapter.remove(tobeDeleteUser);
		adapter.notifyDataSetChanged();

		// 更新消息未读数
		((MainActivity) getActivity()).updateUnreadLabel();

		return true;
	}
	return super.onContextItemSelected(item);
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:22,代码来源:ChatHistoryFragment.java

示例10: sortUserByLastChatTime

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
/**
 * 根据最后一条消息的时间排序
 * 
 * @param usernames
 */
private void sortUserByLastChatTime(List<EMContact> contactList) {
	Collections.sort(contactList, new Comparator<EMContact>() {
		@Override
		public int compare(final EMContact user1, final EMContact user2) {
			EMConversation conversation1 = EMChatManager.getInstance().getConversation(user1.getUsername());
			EMConversation conversation2 = EMChatManager.getInstance().getConversation(user2.getUsername());

			EMMessage user2LastMessage = conversation2.getLastMessage();
			EMMessage user1LastMessage = conversation1.getLastMessage();
			if (user2LastMessage.getMsgTime() == user1LastMessage.getMsgTime()) {
				return 0;
			} else if (user2LastMessage.getMsgTime() > user1LastMessage.getMsgTime()) {
				return 1;
			} else {
				return -1;
			}
		}

	});
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:26,代码来源:ChatHistoryFragment.java

示例11: onSendTxtMsg

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
/****
 * 
 * @param view
 */
public void onSendTxtMsg(String content) {
    try {
        //创建一个消息
        EMMessage msg = EMMessage.createSendMessage(EMMessage.Type.TXT);
        //设置消息的接收方
        msg.setReceipt("bot");
        //设置消息内容。本消息类型为文本消息。 
        
        msg.addBody(new TextMessageBody("我正在浏览你的主页"));
    
        //发送消息
        EMChatManager.getInstance().sendMessage(msg);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:macyuan,项目名称:TAG,代码行数:21,代码来源:Userinfo.java

示例12: initChatOptions

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
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());
}
 
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:22,代码来源:EaseUI.java

示例13: onNewMsg

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
/**
 * 处理新收到的消息,然后发送通知
 * 
 * 开发者可以重载此函数
 * 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);
}
 
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:29,代码来源:EaseNotifier.java

示例14: onNewMesg

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
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));
}
 
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:18,代码来源:EaseNotifier.java

示例15: onConversationInit

import com.easemob.chat.EMChatManager; //导入依赖的package包/类
protected void onConversationInit(){

        // 获取当前conversation对象
        conversation = EMChatManager.getInstance().getConversation(toChatUsername);

        // 把此会话的未读数置为0
        conversation.markAllMessagesAsRead();

        // 初始化db时,每个conversation加载数目是getChatOptions().getNumberOfMessagesLoaded
        // 这个数目如果比用户期望进入会话界面时显示的个数不一样,就多加载一些
        final List<EMMessage> msgs = conversation.getAllMessages();
        int msgCount = msgs != null ? msgs.size() : 0;
        if (msgCount < conversation.getAllMsgCount() && msgCount < pagesize) {
            String msgId = null;
            if (msgs != null && msgs.size() > 0) {
                msgId = msgs.get(0).getMsgId();
            }
            if (chatType == EaseConstant.CHATTYPE_SINGLE) {
                conversation.loadMoreMsgFromDB(msgId, pagesize - msgCount);
            } else {
                conversation.loadMoreGroupMsgFromDB(msgId, pagesize - msgCount);
            }
        }
        
    }
 
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:26,代码来源:EaseChatFragment.java


注:本文中的com.easemob.chat.EMChatManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。