2.登陆
EMChatManager.getInstance().login(name.getText().toString(),
pwd.getText().toString(), new EMCallBack() {
@Override
public void onSuccess() {
Log.v("Lean", "登陆成功");
// 1.保存帐号密码
// save name and pwd
// 2.更新当前用户的nickname 此方法的作用是在ios离线推送时能够显示用户nick
boolean updatenick = EMChatManager.getInstance()
.updateCurrentUserNick(
name.getText().toString());
if (!updatenick) {
// "update current user nick fail"
}
}
@Override
public void onProgress(int progress, String status) {
}
@Override
public void onError(int code, String message) {
Log.v("Lean", "登陆失败");
}
});
3.顶号处理/强制下线处理
private class MyConnectionListener implements EMConnectionListener {
@Override
public void onConnected() {
runOnUiThread(new Runnable() {
@Override
public void run() {
}
});
}
@Override
public void onDisconnected(final int error) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (error == EMError.CONNECTION_CONFLICT) {
// 显示帐号在其他设备登陆dialog
} else {
if (NetUtils.hasNetwork(MainActivity.this))
//"连接不到聊天服务器"
else
//"当前网络不可用,请检查网络设置"
}
}