Java Code Examples for com.easemob.chat.EMMessage#getChatType()

The following examples show how to use com.easemob.chat.EMMessage#getChatType() . 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: DemoHXSDKHelper.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected OnNotificationClickListener getNotificationClickListener() {
    return new OnNotificationClickListener() {

        @Override
        public Intent onNotificationClick(EMMessage message) {
            Intent intent = new Intent(appContext, ChatActivity.class);
            ChatType chatType = message.getChatType();
            if (chatType == ChatType.Chat) { // 单聊信息
                intent.putExtra("userId", message.getFrom());
                intent.putExtra("chatType", ChatActivity.CHATTYPE_SINGLE);
            } else { // 群聊信息
                     // message.getTo()为群聊id
                intent.putExtra("groupId", message.getTo());
                intent.putExtra("chatType", ChatActivity.CHATTYPE_GROUP);
            }
            return intent;
        }
    };
}
 
Example 2
Source File: EaseChatFragment.java    From monolog-android with MIT License 5 votes vote down vote up
/**
 * 转发消息
 * 
 * @param forward_msg_id
 */
protected void forwardMessage(String forward_msg_id) {
    final 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();
        sendTextMessage(content);
        break;
    case IMAGE:
        // 发送图片
        String filePath = ((ImageMessageBody) forward_msg.getBody()).getLocalUrl();
        if (filePath != null) {
            File file = new File(filePath);
            if (!file.exists()) {
                // 不存在大图发送缩略图
                filePath = EaseImageUtils.getThumbnailImagePath(filePath);
            }
            sendImageMessage(filePath);
        }
        break;
    default:
        break;
    }
    
    if(forward_msg.getChatType() == EMMessage.ChatType.ChatRoom){
        EMChatManager.getInstance().leaveChatRoom(forward_msg.getTo());
    }
}
 
Example 3
Source File: EaseChatRowVoicePlayClickListener.java    From monolog-android with MIT License 5 votes vote down vote up
public EaseChatRowVoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity context) {
	this.message = message;
	voiceBody = (VoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = context;
	this.chatType = message.getChatType();
}
 
Example 4
Source File: MainActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    // 主页面收到消息后,主要为了提示未读,实际消息内容需要到chat页面查看

    String from = intent.getStringExtra("from");
    // 消息id
    String msgId = intent.getStringExtra("msgid");
    EMMessage message = EMChatManager.getInstance().getMessage(msgId);
    // 2014-10-22 修复在某些机器上,在聊天页面对方发消息过来时不立即显示内容的bug
    if (ChatActivity.activityInstance != null) {
        if (message.getChatType() == ChatType.GroupChat) {
            if (message.getTo().equals(
                    ChatActivity.activityInstance.getToChatUsername()))
                return;
        } else {
            if (from.equals(ChatActivity.activityInstance
                    .getToChatUsername()))
                return;
        }
    }

    // 注销广播接收者,否则在ChatActivity中会收到这个广播
    abortBroadcast();

    notifyNewMessage(message);

    // 刷新bottom bar消息未读数
    updateUnreadLabel();
    if (currentTabIndex == 0) {
        // 当前页面如果为聊天历史页面,刷新此页面
        if (homefragment != null) {
            homefragment.refresh();
        }
    }

}
 
Example 5
Source File: MainActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@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) {

            // 2014-11-5 修复在某些机器上,在聊天页面对方发送已读回执时不立即显示已读的bug
            if (ChatActivity.activityInstance != null) {
                if (msg.getChatType() == ChatType.Chat) {
                    if (from.equals(ChatActivity.activityInstance
                            .getToChatUsername()))
                        return;
                }
            }

            msg.isAcked = true;
        }
    }

}
 
Example 6
Source File: VoicePlayClickListener.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 
 * @param message
 * @param v
 * @param iv_read_status
 * @param context
 * @param activity
 * @param user
 * @param chatType
 */
public VoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity activity,
		String username) {
	this.message = message;
	voiceBody = (VoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = activity;
	this.chatType = message.getChatType();
}
 
Example 7
Source File: VoicePlayClickListener.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 
 * @param message
 * @param v
 * @param iv_read_status
 * @param context
 * @param activity
 * @param user
 * @param chatType
 */
public VoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity activity,
		String username) {
	this.message = message;
	voiceBody = (VoiceMessageBody) message.getBody();
	this.iv_read_status = iv_read_status;
	this.adapter = adapter;
	voiceIconView = v;
	this.activity = activity;
	this.chatType = message.getChatType();
}
 
Example 8
Source File: DemoHXSDKHelper.java    From school_shop with MIT License 5 votes vote down vote up
@Override
public HXNotifier createNotifier(){
    return new HXNotifier(){
        public synchronized void onNewMsg(final EMMessage message) {
            if(EMChatManager.getInstance().isSlientMessage(message)){
                return;
            }
            
            String chatUsename = null;
            List<String> notNotifyIds = null;
            // 获取设置的不提示新消息的用户或者群组ids
            if (message.getChatType() == ChatType.Chat) {
                chatUsename = message.getFrom();
                notNotifyIds = ((DemoHXSDKModel) hxModel).getDisabledGroups();
            } else {
                chatUsename = message.getTo();
                notNotifyIds = ((DemoHXSDKModel) hxModel).getDisabledIds();
            }

            if (notNotifyIds == null || !notNotifyIds.contains(chatUsename)) {
                // 判断app是否在后台
                if (!EasyUtils.isAppRunningForeground(appContext)) {
                    EMLog.d(TAG, "app is running in backgroud");
                    sendNotification(message, false);
                } else {
                    sendNotification(message, true);

                }
                
                viberateAndPlayTone(message);
            }
        }
    };
}
 
Example 9
Source File: EaseChatFragment.java    From monolog-android with MIT License 4 votes vote down vote up
/**
 * 事件监听,registerEventListener后的回调事件
 * 
 * see {@link EMNotifierEvent}
 */
@Override
public void onEvent(EMNotifierEvent event) {
    switch (event.getEvent()) {
    case EventNewMessage:
        // 获取到message
        EMMessage message = (EMMessage) event.getData();

        String username = null;
        // 群组消息
        if (message.getChatType() == ChatType.GroupChat || message.getChatType() == ChatType.ChatRoom) {
            username = message.getTo();
        } else {
            // 单聊消息
            username = message.getFrom();
        }

        // 如果是当前会话的消息,刷新聊天页面
        if (username.equals(toChatUsername)) {
            messageList.refreshSelectLast();
            // 声音和震动提示有新消息
            EaseUI.getInstance().getNotifier().viberateAndPlayTone(message);
        } else {
            // 如果消息不是和当前聊天ID的消息
            EaseUI.getInstance().getNotifier().onNewMsg(message);
        }

        break;
    case EventDeliveryAck:
    case EventReadAck:
        // 获取到message
        messageList.refresh();
        break;
    case EventOfflineMessage:
        // a list of offline messages
        // List<EMMessage> offlineMessages = (List<EMMessage>)
        // event.getData();
        messageList.refresh();
        break;
    default:
        break;
    }

}
 
Example 10
Source File: ChatActivity.java    From school_shop with MIT License 4 votes vote down vote up
/**
	 * 事件监听
	 * 
	 * see {@link EMNotifierEvent}
     */
    @Override
    public void onEvent(EMNotifierEvent event) {
        switch (event.getEvent()) {
        case EventNewMessage:
        {
            //获取到message
            EMMessage message = (EMMessage) event.getData();
            
            String username = null;
            //群组消息
            if(message.getChatType() == ChatType.GroupChat){
                username = message.getTo();
            }
            else{
                //单聊消息
                username = message.getFrom();
            }

            //如果是当前会话的消息,刷新聊天页面
            if(username.equals(getToChatUsername())){
                refreshUIWithNewMessage();
                //声音和震动提示有新消息
                HXSDKHelper.getInstance().getNotifier().viberateAndPlayTone(message);
            }else{
                //如果消息不是和当前聊天ID的消息
                HXSDKHelper.getInstance().getNotifier().onNewMsg(message);
            }

            break;
        }
//        case EventDeliveryAck:
//        {
//            //获取到message
//            EMMessage message = (EMMessage) event.getData();
//            refreshUI();
//            break;
//        }
//        case EventReadAck:
//        {
//            //获取到message
//            EMMessage message = (EMMessage) event.getData();
//            refreshUI();
//            break;
//        }
        case EventOfflineMessage:
        {
            //a list of offline messages 
            //List<EMMessage> offlineMessages = (List<EMMessage>) event.getData();
            refreshUI();
            break;
        }
        default:
            break;
        }
        
    }