powered by Jive Software

How we come to know who has sent request ..... after setting Roster.SubscriptionMode.manual

Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.manual);

after setting this…when someone send me any request , i can only accept it automatically

but how do i come to know who has send me request ???

how to register a listener for presence packet…??

**like when some listener changes its Status(eg from available to busy) then **

**public void presenceChanged(Presence presence) { **

}

this methord is evoked automatically…

can u plzz exaplin with snippet code

similary how can i find the presence of one who had sent me request…plzzz help

thanks in advance

If you want to handle subscription requests manually, you can register a packet listener to your XMPPConnection

public class PresenceListener implements PacketListener {     public void processPacket(Packet packet) {
        Presence presence = (Presence) packet;
        Presence response = null;         switch (presence.getType()) {
        case subscribe:
            // E.g., Accept the subscribe request
            response = new Presence(Presence.Type.subscribed);
            response.setTo(presence.getFrom());
            xmpp.sendPacket(response);
            break;
        case unsubscribe:
            //...
            break;
        case available:
            //...                        break;         case unavailable:
            /...
            break;
        }
    }
} PacketFilter filter = new PacketTypeFilter(Presence.class);
xmpp.addPacketListener(new PresenceListener(), filter);

and just implement logic when you get a subscribe presence message for example. For presence changes you need to register a RosterListener in a similar way (see http://www.igniterealtime.org/builds/smack/docs/latest/documentation/roster.html).

To find the presence of someone who has just subcribed to you, you need to subscribe to them first, by sending a subscribe presence packet to them. Then you can just check the presence via your roster: xmpp.getRoster().getPresence("somejid@domain.com");

HTH

Dan