Пример #1
0
  private void tryToConnect(boolean create_account) throws ClientException {
    try {
      if (extXMPPConnection.isConnected()) {
        try {
          streamHandler.quickShutdown();
        } catch (Exception e) {
          Log.d(TAG, "conn.shutdown() failed: " + e);
        }
      }
      registerRosterListener();
      boolean need_bind = !streamHandler.isResumePossible();

      if (connectionListener != null)
        extXMPPConnection.removeConnectionListener(connectionListener);
      connectionListener =
          new ConnectionListener() {
            public void connectionClosedOnError(Exception e) {
              onDisconnected(e);
            }

            public void connectionClosed() {

              updateConnectionState(ConnectionState.OFFLINE);
            }

            public void reconnectingIn(int seconds) {}

            public void reconnectionFailed(Exception e) {}

            public void reconnectionSuccessful() {}
          };
      extXMPPConnection.addConnectionListener(connectionListener);

      extXMPPConnection.connect(need_bind);
      if (!extXMPPConnection.isAuthenticated()) {
        if (create_account) {
          AccountManager am = new AccountManager(extXMPPConnection);
          am.createAccount(configuration.userName, configuration.password);
        }
        extXMPPConnection.login(
            configuration.userName, configuration.password, configuration.ressource);
      }
      if (need_bind) {
        streamHandler.notifyInitialLogin();
        setStatusFromConfig();
      }

    } catch (Exception e) {

      throw new ClientException("tryToConnect failed", e);
    }
  }
Пример #2
0
 public boolean isAuthenticated() {
   if (extXMPPConnection != null) {
     return (extXMPPConnection.isConnected() && extXMPPConnection.isAuthenticated());
   }
   return false;
 }