Create session with User & Sign In to QuickBlox Chat
// 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) {
}
});
To handle different connection states use 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);