powered by Jive Software

Detects incoming subscription request

I am setting subscription mode to manual:


I know how to get a list of roster. But, how do I get the new subcriptions requests

and accept them manually ?

You’'ll need to listen out for them and when received peform whatever logic you want.

To listen out for Subscription packets you could do something like

class PresenceListener implements PacketListener {

public void processPacket(Packet packet) {

Presence presence = (Presence)packet;

Presence.Type presenceType = presence.getType();

if(presenceType == Presence.Type.SUBSCRIBE) {

// do something with subscribing


if(presenceType == Presence.Type.SUBSCRIBED) {

// do something with letting user know someone has subscribed





You’'ll then need to add this class as a listener to your connection

PacketTypeFilter filter = new PacketTypeFilter(Presence.class);

conn.addPacketerListener(new PresenceListener(), filter);




I have alreadt added the listener with Message.Class.

Now, if I add Presence.Class. Then, how do I detect on incoming packet which

class it belongs to ?

Your connection object is able to add multiple listeners. This way you can listen out for Message Packets, Presence Packets IQ packets and anything else you may want to listen for.

If you’'ve already added a Message Listener to your connection just add the Presence Listener above after. So

PacketTypeFilter filter;

filter = new PacketTyperFilter(Message.class);

connection.addPacketListener(new MessageListener(), filter);

filter = new PacketTyperFilter(Presence.class);

connection.addPacketListener(new PresenceListener(), filter);