how to add roster with subscription mode “both”

前端 未结 5 1405
失恋的感觉
失恋的感觉 2020-12-24 03:40

i\'m using smack 3.1.0, and when i add a roster,i can\'t get subscription \"both\". who can help me? below is my code:

Roster.setDefaultSubscriptionMode(Rost         


        
5条回答
  •  鱼传尺愫
    2020-12-24 04:08

    Same problem I was face but I got the solution how subscribe set 'both'

    Below is sending subscription to user, when you added the user

     Presence pres = new Presence(Presence.Type.subscribed);
            pres.setPriority(24);
            pres.setMode(Presence.Mode.available);
            pres.setTo(friendJid);
    
            RoosterConnection.getConnection().sendStanza(pres);
    

    and Receiving end put below method in connection class and presenceChanged is default method of RosterListener.

     @Override
    public void presenceChanged(Presence presence) {
        mBus.post(presence);
        try {
            Presence pres = new Presence(Presence.Type.subscribed);
            pres.setTo(presence.getFrom());
            RoosterConnection.getConnection().sendStanza(pres);
        } catch (SmackException.NotConnectedException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    

提交回复
热议问题