com.easemob.exceptions.EaseMobException Java Examples

The following examples show how to use com.easemob.exceptions.EaseMobException. 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: EaseChatRowFile.java    From monolog-android with MIT License 6 votes vote down vote up
@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 #2
Source File: ChatSingleSettingActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 移出免打扰
 * 
 * @param tobeRemoveUser
 */
private void removeOutBlacklist(final String tobeRemoveUser) {

    try {

        // 移出黑民单
        EMContactManager.getInstance().deleteUserFromBlackList(
                tobeRemoveUser);
        iv_switch_block_groupmsg.setVisibility(View.INVISIBLE);
        iv_switch_unblock_groupmsg.setVisibility(View.VISIBLE);
    } catch (EaseMobException e) {
        e.printStackTrace();
        runOnUiThread(new Runnable() {
            public void run() {

                Toast.makeText(getApplicationContext(), "设置失败",
                        Toast.LENGTH_SHORT).show();
            }
        });
    }
}
 
Example #3
Source File: EaseContactListFragment.java    From monolog-android with MIT License 5 votes vote down vote up
/**
 * 把user移入到黑名单
 */
protected void moveToBlacklist(final String username){
    final ProgressDialog pd = new ProgressDialog(getActivity());
    String st1 = getResources().getString(R.string.Is_moved_into_blacklist);
    final String st2 = getResources().getString(R.string.Move_into_blacklist_success);
    final String st3 = getResources().getString(R.string.Move_into_blacklist_failure);
    pd.setMessage(st1);
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    new Thread(new Runnable() {
        public void run() {
            try {
                //加入到黑名单
                EMContactManager.getInstance().addUserToBlackList(username,false);
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getActivity(), st2, 0).show();
                        refresh();
                    }
                });
            } catch (EaseMobException e) {
                e.printStackTrace();
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getActivity(), st3, 0).show();
                    }
                });
            }
        }
    }).start();
    
}
 
Example #4
Source File: ChatSingleSettingActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 把user移入到免打扰
 */
private void moveToBlacklist(final String username) {

    new Thread(new Runnable() {
        public void run() {
            try {
                // 加入到黑名单
                EMContactManager.getInstance().addUserToBlackList(username,
                        false);
                runOnUiThread(new Runnable() {
                    public void run() {
                        progressDialog.dismiss();
                        iv_switch_block_groupmsg
                                .setVisibility(View.VISIBLE);
                        iv_switch_unblock_groupmsg
                                .setVisibility(View.INVISIBLE);

                    }
                });
            } catch (final EaseMobException e) {
                e.printStackTrace();
                runOnUiThread(new Runnable() {
                    public void run() {
                        progressDialog.dismiss();
                        Toast.makeText(getApplicationContext(),
                                "设置失败,原因:" + e.toString(),
                                Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    }).start();

}
 
Example #5
Source File: ChatActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 加入到黑名单
 * 
 * @param username
 */
private void addUserToBlacklist(String username) {
    try {
        EMContactManager.getInstance().addUserToBlackList(username, false);
        Toast.makeText(getApplicationContext(), "移入黑名单成功",
                Toast.LENGTH_SHORT).show();
    } catch (EaseMobException e) {
        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "移入黑名单失败",
                Toast.LENGTH_SHORT).show();
    }
}
 
Example #6
Source File: ChatActivity.java    From school_shop with MIT License 5 votes vote down vote up
/**
 * 加入到黑名单
 * 
 * @param username
 */
private void addUserToBlacklist(final String username) {
    final ProgressDialog pd = new ProgressDialog(this);
       pd.setMessage(getString(R.string.Is_moved_into_blacklist));
       pd.setCanceledOnTouchOutside(false);
       pd.show();
    new Thread(new Runnable() {
           public void run() {
               try {
                   EMContactManager.getInstance().addUserToBlackList(username, false);
                   runOnUiThread(new Runnable() {
                       public void run() {
                           pd.dismiss();
                           Toast.makeText(getApplicationContext(), R.string.Move_into_blacklist_success, 0).show();
                       }
                   });
               } catch (EaseMobException e) {
                   e.printStackTrace();
                   runOnUiThread(new Runnable() {
                       public void run() {
                           pd.dismiss();
                           Toast.makeText(getApplicationContext(), R.string.Move_into_blacklist_failure, 0).show();
                       }
                   });
               }
           }
       }).start();
}
 
Example #7
Source File: EaseChatRowText.java    From monolog-android with MIT License 4 votes vote down vote up
@Override
    public void onSetUpView() {
        TextMessageBody txtBody = (TextMessageBody) message.getBody();
        Spannable span = EaseSmileUtils.getSmiledText(context, txtBody.getMessage());
        // 设置内容
        contentView.setText(span, BufferType.SPANNABLE);

        if (message.direct == EMMessage.Direct.SEND) {
            setMessageSendCallback();
            switch (message.status) {
            case CREATE: 
                progressBar.setVisibility(View.VISIBLE);
                statusView.setVisibility(View.GONE);
                // 发送消息
//                sendMsgInBackground(message);
                break;
            case SUCCESS: // 发送成功
                progressBar.setVisibility(View.GONE);
                statusView.setVisibility(View.GONE);
                break;
            case FAIL: // 发送失败
                progressBar.setVisibility(View.GONE);
                statusView.setVisibility(View.VISIBLE);
                break;
            case INPROGRESS: // 发送中
                progressBar.setVisibility(View.VISIBLE);
                statusView.setVisibility(View.GONE);
                break;
            default:
               break;
            }
        }else{
            if(!message.isAcked() && message.getChatType() == ChatType.Chat){
                try {
                    EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    message.isAcked = true;
                } catch (EaseMobException e) {
                    e.printStackTrace();
                }
            }
        }
    }
 
Example #8
Source File: ChatRoomSettingActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
private void initData() {

        // 获取传过来的groupid
        groupId = getIntent().getStringExtra("groupId");
        // 获取本地该群数据
        group = EMGroupManager.getInstance().getGroup(groupId);
        if (group == null) {
            try {
                // 去网络中查找该群
                group = EMGroupManager.getInstance()
                        .getGroupFromServer(groupId);
                if (group == null) {
                    Toast.makeText(ChatRoomSettingActivity.this, "该群已经被解散...",
                            Toast.LENGTH_SHORT).show();
                    setResult(100);
                    finish();
                    return;

                }
            } catch (EaseMobException e) {

                e.printStackTrace();
                return;
            }

        }

        // 获取封装的群名(里面封装了显示的群名和群组成员的信息)
        String group_name_temp = group.getGroupName();
        // 转化成json,然后解析
        jsonObject = JSONObject.parseObject(group_name_temp);
        // 获取显示的群名
        group_name = jsonObject.getString("groupname");
        // 获取群成员信息
        jsonarray = jsonObject.getJSONArray("jsonArray");

        tv_groupname.setText(group_name);
        m_total = jsonarray.size();
        tv_m_total.setText("(" + String.valueOf(m_total) + ")");
        // 解析群组成员信息
        for (int i = 0; i < m_total; i++) {
            JSONObject json = jsonarray.getJSONObject(i);
            User user = new User();
            user.setUsername(json.getString("hxid"));
            user.setAvatar(json.getString("avatar"));
            user.setNick(json.getString("nick"));
            members.add(user);
        }
        // 显示群组成员头像和昵称
        showMembers(members);
        // 判断是否是群主,是群主有删成员的权限,并显示减号按钮
        if (hxid.equals(group.getOwner())) {
            is_admin = true;
        }

        re_change_groupname.setOnClickListener(this);
        rl_switch_chattotop.setOnClickListener(this);
        rl_switch_block_groupmsg.setOnClickListener(this);

        re_clear.setOnClickListener(this);

        exitBtn.setOnClickListener(this);

    }
 
Example #9
Source File: RegisterActivity.java    From FanXin-based-HuanXin with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 注册
 * 
 * @param view
 */
public void register(final String hxid, final String password) {
    // String st1 = getResources().getString(
    // R.string.User_name_cannot_be_empty);
    // String st2 = getResources()
    // .getString(R.string.Password_cannot_be_empty);
    // String st3 = getResources().getString(
    // R.string.Confirm_password_cannot_be_empty);
    // String st4 = getResources().getString(R.string.Two_input_password);
    // String st5 = getResources().getString(R.string.Is_the_registered);
    final String st6 = getResources().getString(
            R.string.Registered_successfully);

    if (!TextUtils.isEmpty(hxid) && !TextUtils.isEmpty(password)) {

        final String st7 = getResources().getString(
                R.string.network_anomalies);
        final String st8 = getResources().getString(
                R.string.User_already_exists);
        final String st9 = getResources().getString(
                R.string.registration_failed_without_permission);
        final String st10 = getResources().getString(
                R.string.Registration_failed);
        new Thread(new Runnable() {
            public void run() {
                try {
                    // 调用sdk注册方法
                    EMChatManager.getInstance().createAccountOnServer(hxid,
                            password);
                    runOnUiThread(new Runnable() {
                        public void run() {
                            if (!RegisterActivity.this.isFinishing())
                                dialog.dismiss();
                            // 保存用户名
                            MYApplication.getInstance().setUserName(hxid);

                            Toast.makeText(getApplicationContext(), st6, 0)
                                    .show();
                            finish();
                        }
                    });
                } catch (final EaseMobException e) {
                    runOnUiThread(new Runnable() {
                        public void run() {
                            if (!RegisterActivity.this.isFinishing())
                                dialog.dismiss();
                            int errorCode = e.getErrorCode();
                            if (errorCode == EMError.NONETWORK_ERROR) {
                                Toast.makeText(getApplicationContext(),
                                        st7, Toast.LENGTH_SHORT).show();
                            } else if (errorCode == EMError.USER_ALREADY_EXISTS) {
                                Toast.makeText(getApplicationContext(),
                                        st8, Toast.LENGTH_SHORT).show();
                            } else if (errorCode == EMError.UNAUTHORIZED) {
                                Toast.makeText(getApplicationContext(),
                                        st9, Toast.LENGTH_SHORT).show();
                            } else {
                                Toast.makeText(getApplicationContext(),
                                        st10 + e.getMessage(),
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
            }
        }).start();

    }
}
 
Example #10
Source File: RegisterActivity.java    From school_shop with MIT License 4 votes vote down vote up
/**
 * 注册
 * 
 * @param view
 */
public void register(View view) {
	String st1 = getResources().getString(R.string.User_name_cannot_be_empty);
	String st2 = getResources().getString(R.string.Password_cannot_be_empty);
	String st3 = getResources().getString(R.string.Confirm_password_cannot_be_empty);
	String st4 = getResources().getString(R.string.Two_input_password);
	String st5 = getResources().getString(R.string.Is_the_registered);
	final String st6 = getResources().getString(R.string.Registered_successfully);
	final String username = userNameEditText.getText().toString().trim();
	final String pwd = passwordEditText.getText().toString().trim();
	String confirm_pwd = confirmPwdEditText.getText().toString().trim();
	if (TextUtils.isEmpty(username)) {
		Toast.makeText(this, st1, Toast.LENGTH_SHORT).show();
		userNameEditText.requestFocus();
		return;
	} else if (TextUtils.isEmpty(pwd)) {
		Toast.makeText(this, st2, Toast.LENGTH_SHORT).show();
		passwordEditText.requestFocus();
		return;
	} else if (TextUtils.isEmpty(confirm_pwd)) {
		Toast.makeText(this, st3, Toast.LENGTH_SHORT).show();
		confirmPwdEditText.requestFocus();
		return;
	} else if (!pwd.equals(confirm_pwd)) {
		Toast.makeText(this, st4, Toast.LENGTH_SHORT).show();
		return;
	}

	if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(pwd)) {
		final ProgressDialog pd = new ProgressDialog(this);
		pd.setMessage(st5);
		pd.show();
		final String st7 = getResources().getString(R.string.network_anomalies);
		final String st8 = getResources().getString(R.string.User_already_exists);
		final String st9 = getResources().getString(R.string.registration_failed_without_permission);
		final String st10 = getResources().getString(R.string.Registration_failed);
		new Thread(new Runnable() {
			public void run() {
				try {
					// 调用sdk注册方法
					EMChatManager.getInstance().createAccountOnServer(username, pwd);
					runOnUiThread(new Runnable() {
						public void run() {
							if (!RegisterActivity.this.isFinishing())
								pd.dismiss();
							// 保存用户名
							MyApplication.getInstance().setUserName(username);
							Toast.makeText(getApplicationContext(), st6, 0).show();
							finish();
						}
					});
				} catch (final EaseMobException e) {
					runOnUiThread(new Runnable() {
						public void run() {
							if (!RegisterActivity.this.isFinishing())
								pd.dismiss();
							int errorCode=e.getErrorCode();
							if(errorCode==EMError.NONETWORK_ERROR){
								Toast.makeText(getApplicationContext(), st7, Toast.LENGTH_SHORT).show();
							}else if(errorCode==EMError.USER_ALREADY_EXISTS){
								Toast.makeText(getApplicationContext(), st8, Toast.LENGTH_SHORT).show();
							}else if(errorCode==EMError.UNAUTHORIZED){
								Toast.makeText(getApplicationContext(), st9, Toast.LENGTH_SHORT).show();
							}else{
								Toast.makeText(getApplicationContext(), st10 + e.getMessage(), Toast.LENGTH_SHORT).show();
							}
						}
					});
				}
			}
		}).start();

	}
}
 
Example #11
Source File: LoginActivity.java    From school_shop with MIT License 4 votes vote down vote up
private void processContactsAndGroups() throws EaseMobException {
    // demo中简单的处理成每次登陆都去获取好友username,开发者自己根据情况而定
    List<String> usernames = EMContactManager.getInstance().getContactUserNames();
    EMLog.d("roster", "contacts size: " + usernames.size());
    Map<String, User> userlist = new HashMap<String, User>();
    for (String username : usernames) {
        User user = new User();
        user.setUsername(username);
        setUserHearder(username, user);
        userlist.put(username, user);
    }
    // 添加user"申请与通知"
    User newFriends = new User();
    newFriends.setUsername(Constants.NEW_FRIENDS_USERNAME);
    String strChat = getResources().getString(R.string.Application_and_notify);
    newFriends.setNick(strChat);
    
    userlist.put(Constants.NEW_FRIENDS_USERNAME, newFriends);
    // 添加"群聊"
    User groupUser = new User();
    String strGroup = getResources().getString(R.string.group_chat);
    groupUser.setUsername(Constants.GROUP_USERNAME);
    groupUser.setNick(strGroup);
    groupUser.setHeader("");
    userlist.put(Constants.GROUP_USERNAME, groupUser);

    // 存入内存
    MyApplication.getInstance().setContactList(userlist);
    System.out.println("----------------"+userlist.values().toString());
    // 存入db
    UserDao dao = new UserDao(LoginActivity.this);
    List<User> users = new ArrayList<User>(userlist.values());
    dao.saveContactList(users);
    
    //获取黑名单列表
    List<String> blackList = EMContactManager.getInstance().getBlackListUsernamesFromServer();
    //保存黑名单
    EMContactManager.getInstance().saveBlackList(blackList);

    // 获取群聊列表(群聊里只有groupid和groupname等简单信息,不包含members),sdk会把群组存入到内存和db中
    EMGroupManager.getInstance().getGroupsFromServer();
}