Neeta
April 9, 2008, 6:09pm
#1
Hi,
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 );
authorize.setTo(from);
connection.sendPacket(authorize);
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 );
auth.setTo(from);
connection.sendPacket(auth);
This is not working. How can I reject a friend request in Smack?
Thanks,
Neeta
if (presence.getType() == Presence.Type.subscribe) {
// send subscription deny packet
Presence response = new Presence(Presence.Type.unsubscribe);
response.setTo(from);
con.sendPacket(response);
}
Don’t put plus-signs in there.
Neeta
April 10, 2008, 5:17pm
#3
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.
Neeta
Please refer the JavaDocs for explanation of such things. It comes with the smack libraries for easy offline reading.
http://www.igniterealtime.org/builds/smack/docs/latest/javadoc/org/jivesoftware/ 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.