登录聊天
使用用户创建会话并登录 QuickBlox 聊天
// Initialise Chat service
QBChatService chatService = QBChatService.getInstance();
final QBUser user = new QBUser("garrysantos", "garrysantospass");
QBAuth.createSession(user, new QBEntityCallback<QBSession>() {
@Override
public void onSuccess(QBSession session, Bundle params) {
// success, login to chat
user.setId(session.getUserId());
chatService.login(qbUser, new QBEntityCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(QBResponseException errors) {
}
});
}
@Override
public void onError(QBResponseException errors) {
}
});
要处理不同的连接状态,请使用 ConnectionListener:
ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void connected(XMPPConnection connection) {
}
@Override
public void authenticated(XMPPConnection connection) {
}
@Override
public void connectionClosed() {
}
@Override
public void connectionClosedOnError(Exception e) {
// connection closed on error. It will be established soon
}
@Override
public void reconnectingIn(int seconds) {
}
@Override
public void reconnectionSuccessful() {
}
@Override
public void reconnectionFailed(Exception e) {
}
};
QBChatService.getInstance().addConnectionListener(connectionListener);