powered by Jive Software

Not receiving Presence.Type.subscribed packet


#1

I want add presence subscription functionality in my app. I have followed this : https://stackoverflow.com/questions/5802607/how-to-add-roster-with-subscription-mode-both

Both users need to subscribe to each other and accept the subscription request they received. Let’s call them Alice and Bob. Alice sends a subscription request to Bob:

Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo('bob@example.com');
connection.sendPacket(subscribe);

When Bob receives the request, he approves it:

Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo('alice@example.com');
connection.sendPacket(subscribed);

Bob may also be interested in Alice’s presence, so he subscribes to her:

Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setTo('alice@example.com');
connection.sendPacket(subscribe);

And Alice needs to approve Bob’s request:

Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo('bob@example.com');
connection.sendPacket(subscribed);

I can track Presence.Type.subscribe packet in my stanzaListener but i am not receiving the packets for Presence.Type.subscribed. I have added the stanzaListener as follow:

            mConnection.addAsyncStanzaListener(stanzaListener, new StanzaTypeFilter(Presence.class));

StanzaListener class :

 private StanzaListener stanzaListener = new StanzaListener() {
        @Override
        public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {
            Presence presence = (Presence) packet;
            switch (presence.getType()) {   
                case subscribe: {
                    //do some work
                    //I can receive subscribe packet 
                    break;
                }
                case subscribed: {
                    Log.d(TAG, "processStanza: subscribed");
                   //do some work
                   // i am not receiving subscribed packet
                    break;
                }              
            }
        }
    };

Any help is highly appreciated.