本文整理汇总了Java中com.easemob.chat.EMChatManager类的典型用法代码示例。如果您正苦于以下问题:Java EMChatManager类的具体用法?Java EMChatManager怎么用?Java EMChatManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EMChatManager类属于com.easemob.chat包,在下文中一共展示了EMChatManager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: sendMessage
import com.easemob.chat.EMChatManager; //导入依赖的package包/类
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();
}
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:17,代码来源:EaseChatFragment.java
示例17: init
import com.easemob.chat.EMChatManager; //导入依赖的package包/类
/**
* 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();
}
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:23,代码来源:EaseChatMessageList.java
示例18: onBubbleClick
import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@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);
}
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:26,代码来源:EaseChatRowImage.java
示例19: onBubbleClick
import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@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();
}
}
}
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:23,代码来源:EaseChatRowFile.java
示例20: onBubbleClick
import com.easemob.chat.EMChatManager; //导入依赖的package包/类
@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);
}
开发者ID:huijimuhe,项目名称:monolog-android,代码行数:20,代码来源:EaseChatRowVideo.java
注:本文中的com.easemob.chat.EMChatManager类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论