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

The following examples show how to use com.easemob.chat.EMMessage#setTo() . 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: MainActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onInvitationReceived(String groupId, String groupName,
        String inviter, String reason) {

    // 被邀请
    String st3 = getResources().getString(
            R.string.Invite_you_to_join_a_group_chat);
    User user = MYApplication.getInstance().getContactList()
            .get(inviter);
    if (user != null) {
        EMMessage msg = EMMessage.createReceiveMessage(Type.TXT);
        msg.setChatType(ChatType.GroupChat);
        msg.setFrom(inviter);
        msg.setTo(groupId);
        msg.setMsgId(UUID.randomUUID().toString());
        msg.addBody(new TextMessageBody(user.getNick() + st3));
        msg.setAttribute("useravatar", user.getAvatar());
        msg.setAttribute("usernick", user.getNick());
        // 保存邀请消息
        EMChatManager.getInstance().saveMessage(msg);
        // 提醒新消息
        EMNotifier.getInstance(getApplicationContext())
                .notifyOnNewMsg();
    }
    runOnUiThread(new Runnable() {
        public void run() {
            updateUnreadLabel();
            // 刷新ui
            if (currentTabIndex == 0)
                homefragment.refresh();
            // if (CommonUtils.getTopActivity(MainActivity.this).equals(
            // GroupsActivity.class.getName())) {
            // GroupsActivity.instance.onResume();
            // }
        }
    });

}
 
Example 2
Source File: MainActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onApplicationAccept(String groupId, String groupName,
        String accepter) {
    String st4 = getResources().getString(
            R.string.Agreed_to_your_group_chat_application);
    // 加群申请被同意
    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 + st4));
    // 保存同意消息
    EMChatManager.getInstance().saveMessage(msg);
    // 提醒新消息
    EMNotifier.getInstance(getApplicationContext()).notifyOnNewMsg();

    runOnUiThread(new Runnable() {
        public void run() {
            updateUnreadLabel();
            // 刷新ui
            if (currentTabIndex == 0)
                homefragment.refresh();
            // if (CommonUtils.getTopActivity(MainActivity.this).equals(
            // GroupsActivity.class.getName())) {
            // GroupsActivity.instance.onResume();
            // }
        }
    });
}