How to add reject buddy support


When someone (username:X) wants to add me (username:Me) as a buddy I get a add buddy accept or reject dialog. How can I reject this buddy request?

As if I want to accept friend request from X I can do:

Presence authorize = new Presence(Presence.Type.SUBSCRIBED);



This is working fine. But if I wan’t to reject the friend request from X I am doing:

Presence auth = new Presence(Presence.Type.UNSUBSCRIBED);



This is not working. How can I reject a friend request in Smack?



if (presence.getType() == Presence.Type.subscribe) {
        // send subscription deny packet
        Presence response = new Presence(Presence.Type.unsubscribe);

Don’t put plus-signs in there.

I am not sure how these + are added with undubscribed. Some copy paste issue. But I saw you are using “unsubscribe” instead. I will try using “unsubscribe” insted of unsubscribed and will update you if it worked for me.

Thanks a lot for your reply.


Please refer the JavaDocs for explanation of such things. It comes with the smack libraries for easy offline reading. smack/packet/Presence.html

public class Presence

extends Packet

Represents XMPP presence packets. Every presence packet has a type, which is one of the following values:

available – (Default) indicates the user is available to receive messages.

unavailable – the user is unavailable to receive messages.

subscribe – request subscription to recipient’s presence.

subscribed – grant subscription to sender’s presence.

unsubscribe – request removal of subscription to sender’s presence. unsubscribed – grant removal of subscription to sender’s presence.

error – the presence packet contains an error message.