title: Android with Asmack -How to check user presence status in XMPP in android?
body: <p>I use this <a href="https://stackoverflow.com/questions/14453089/xmpp-asmack-how-can-i-get-the-current-user-state-offline-online-away-etc">XMPP aSmack - How can I get the current user state (offline/online/away/etc.)?</a><br>
  Code for to connect with ejabbered and login is</p>
  
  <pre><code>Class.forName("org.jivesoftware.smack.ReconnectionManager");
  System.setProperty("smack.debugEnabled", "true");
  ConnectionConfiguration connConfig = new ConnectionConfiguration(
          XmppUtils.HOST, XmppUtils.PORT, XmppUtils.SERVICE);
  connConfig.setSecurityMode(SecurityMode.disabled);
  connConfig.setSendPresence(true);
  XMPPConnection   connection = new XMPPConnection(connConfig);
  SASLAuthentication.supportSASLMechanism("PLAIN");
  connConfig.setSASLAuthenticationEnabled(true);
  connection.connect();                   
  connection.login(Fblogin.fb_id, XmppUtils.PASSWORD);
  Presence presence = new Presence(Presence.Type.available);
  connection.sendPacket(presence);
  setConnection(connection);
  
  //Check the user onlcine or offline
  Presence userFromServer=connection.getRoster().getPresence(TOCHATUSERNAME+"/Smack");
  final int userState = XmppUtils.retrieveState(userFromServer.getMode(), userFromServer.isAvailable());
  
  // Set the state
  getActivity().runOnUiThread(new Runnable() {
       @Override
       public void run() {
           if (userState==0) {
                  txt_membersgname.setText("offline");
           } else if (userState==1) {
                  txt_membersgname.setText("online");
           } else if (userState==2) {
                  txt_membersgname.setText("Busy");
           }
      }
  });
  
  
  public static int retrieveState(Mode userMode, boolean isOnline) {
      /** 0 for offline, 1 for online, 2 for away,3 for busy*/
      int userState = 0; // default return value
      if (userMode == Mode.dnd) {
          Log.e("busy", "busy");
          userState = 3;
      } else if (userMode == Mode.away || userMode == Mode.xa) {
          userState =2;
      } else if (isOnline) {
          Log.e("online", "online");
          userState = 1;
      }
      return userState;
  }
  </code></pre>
  
  <p>I always get Presence  unavailable but if i use below code it works correct </p>
  
  <pre><code>Presence userFromServer=connection.getRoster().getPresence(connection.getUser());
  </code></pre>
  
  <p>what am i doing wrong  so how can i get other users Presence ?</p>