4

In my application when I send a request to any friend using this code..

try {               
                roster.createEntry(idExtension, nickname, null);
                roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
                Presence subscribe = new Presence(Presence.Type.subscribe);
                subscribe.setTo(idExtension);               
                connection.sendPacket(subscribe);


                return true;
            } catch (XMPPException e) {
                System.err.println("Error in adding friend");
                return false;
            }

then the subscription says "NONE" in both the friends rosters.

But it should be "TO" and "FROM".

But if For the same process I use this code -

try {               
                roster.createEntry(idExtension, nickname, null);
                roster.setSubscriptionMode(Roster.SubscriptionMode.manual);
                Presence subscribed = new Presence(Presence.Type.subscribed);
                subscribed.setTo(idExtension);              
                connection.sendPacket(subscribed);


                return true;
            } catch (XMPPException e) {
                System.err.println("Error in adding friend");
                return false;
            }

Then it gives me right result which i should get in the previous case.

Please tell me why I am not getting the same in SUBSCRIBE mode.

Thanks

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
  • hi Gaurav, are succeeded in file transfer ? if yes then please help me to do the same. i am stuck with this file transfer. – Juned Nov 12 '12 at 06:21
  • @juned No brother I have kept that thing aside.now I have moved on to other functionality. Please help me in this - http://stackoverflow.com/questions/13338515/logout-to-add-a-friend-in-xmpp-smack#comment18202063_13338515 – Gaurav Arora Nov 12 '12 at 06:33
  • yeah sure,Actually i found you on Harryjoy's blog.so i thought you had done with file transfer. Anyways No Problem :) – Juned Nov 12 '12 at 06:42
  • @juned Do you find any solution for my problem ?? which I mentioned in the above link ?? – Gaurav Arora Nov 12 '12 at 06:49
  • Nope, actually i didn't implemented that feature but i suggest you to find about how to refresh the friend list to see the recently added user in friend list. Do this thing using service in background and refresh accordingly. This is my general thought but once i'll work on this i give you complete solution. – Juned Nov 12 '12 at 07:06

1 Answers1

3

I guess you are not getting the meaning of type in Presence.

subscribe -- The sender wishes to subscribe to the recipient's presence.

subscribed -- The sender has allowed the recipient to receive their presence.

So when you send the first one you request a user to let you subscribe to his presence events and until he has not allowed you to do so the subscription type is none.

In second case you allowed the user to subscribe to your presence, that is you give him permission to listen to your presence, and thus you get the subscription type.

Community
  • 1
  • 1
Harry Joy
  • 58,650
  • 30
  • 162
  • 207
  • On the very first case when i send a subscription request now I am using SUBSCRIBE and then a notification goes to the user. On that notification's allow button I change the presence to SUBSCRIBED, but in the open fire subscription list I see only TO/FROM. But I want BOTH status. How can achieve the same. – Gaurav Arora Oct 20 '12 at 10:45
  • You have to do this procedure from both ends. Sp total of 4 presence will take place in this, in which 2 will of type Subscribe and other 2 will be Subscribed. – Harry Joy Oct 22 '12 at 04:44
  • Can I have a chat session with you for 10mins – Gaurav Arora Oct 22 '12 at 04:47
  • Ist step - the person who wants to add will send - Subscribe packet IInd step - the person who will receive it will send - SUBSCRIBED packet. After that what will happen??? – Gaurav Arora Oct 22 '12 at 12:15
  • then do the reverse process: person who has received the request will now send SUBSCRIBE and the other person will respond by SUBSCRIBED. – Harry Joy Oct 22 '12 at 12:18
  • Sorry to say I am bit confused bro. Let X wants to add Y 1st step :- X will send SUSCRIBE packet 2nd step :- After receiving Y will send SUBSCRIBED packet Now Please check my 2 steps and write 3rd and 4th one Sorry for the inconvinience bro. Please reply – Gaurav Arora Oct 23 '12 at 03:40
  • Now 3rd step Y will send SUBSCRIBE to X and 4th step on receiving X will send SUBSCRIBED to Y. – Harry Joy Oct 23 '12 at 04:22
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/18442/discussion-between-gaurav-arora-and-harry-joy) – Gaurav Arora Oct 23 '12 at 04:26
  • Please help me in this - http://stackoverflow.com/questions/13338515/logout-to-add-a-friend-in-xmpp-smack#comment18202063_13338515 – Gaurav Arora Nov 12 '12 at 07:02
  • Hello Gaurav and Harry ,if you people have done it completly can you please share the complete 4 step subscription mechanism. I am new to it and lacking in understanding proper way to implement it.Please help me.Thanks a lot – Pawan Gupta Oct 09 '13 at 10:32