powered by Jive Software

Presence Unavailable and RosterListener

When I sent my presence type to unavailable, the rosterlistener is not able to listen to changes in the presence in my roster? here is my code

import java.util.Collection;

import org.jivesoftware.smack.;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Presence;
import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smackx.
;
public class Gtalk {

/**

  • @param args
    */
    public static void main(String[] args) {

    try
    {
    // Create the configuration for this new connection
    ConnectionConfiguration config = new ConnectionConfiguration(“talk.google.com”, 5222,“gmail.com”);
    config.setCompressionEnabled(true);
    config.setSASLAuthenticationEnabled(true);
    XMPPConnection connection = new XMPPConnection(config);
    // Connect

     connection.connect();
    
     connection.login("*****************", "********************");
    
     Presence presence = new org.jivesoftware.smack.packet.Presence(
             Presence.Type.unavailable,
             "",
             24,
             Presence.Mode.available);        
     connection.sendPacket(presence);        
    
     // Send it        
    
     Roster roster = connection.getRoster();
    
    
     RosterListener rosterListener= new RosterListener() {
          public void entriesAdded(Collection<String> addresses) {}
          public void entriesDeleted(Collection<String> addresses) {}
          public void entriesUpdated(Collection<String> addresses) {}
          public void presenceChanged(Presence presence) {
              System.out.println("Presence changed: " + presence.getFrom() + " " + presence);                 
          }
         
      };
      roster.addRosterListener(rosterListener);
     
     do {          
      Thread.sleep(1000);  //keep the program runnin
        System.out.flush();      
     }while(true);
    
     //connection.disconnect();
    

    }catch (Exception e){

    }

}

}

You’re adding the RosterListener a bit too late. Do it right after you’ve logged in.

I did but it did not work. Let me tell you what is happening. When I set my presence to unavailable , the rosterlistener get’s the presnece of my roster the first time, however subsequently when the presence of a user on my roster changes it does not get picked up.

Thanks