Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top