简体   繁体   中英

How to parse custom roster query response in Android XMPP client with SMACK

As for now I have very little understanding of XMPP and SMACK in general so please excuse me if my questions are imprecise.

Upon login I receive packet with roster that looks as follows:

<iq id="8CiUQ-1" type="result">
    <query xmlns="jabber:iq:roster">
    <item jid="625126126@saomeapp-test.cloudapp.net" name="Aziez" subscription="both" msgblock="none"/>
    <item jid="547657221@saomeapp-test.cloudapp.net" name="Kmil" subscription="both" msgblock="none"/>
    <item jid="553269257@saomeapp-test.cloudapp.net" name="grzegorz" subscription="both" msgblock="none"/>
    <item jid="683494364@saomeapp-test.cloudapp.net" name="Wiktor2" subscription="both" msgblock="none"/>
    <item jid="602914857@saomeapp-test.cloudapp.net" name="Art" subscription="both" msgblock="none"/>
    <item jid="634926524@saomeapp-test.cloudapp.net" name="ml" subscription="both" msgblock="none"/>
    </query>
</iq>

I know this because I can see this packet printed to my logcat under SMACK tag.

I need to access msgblock parameter. org.jivesoftware.smack.RosterEntry class will not have a getter for msgblock parameter as it is custom for this server implementation (I suppose). How do I access msgblock parameter then?

Here is what I tried:

I called: mConnection.addPacketListener(new RosterPacketListener(), new RosterPacketFilter()); where mConnection is an instance of org.jivesoftware.smack.XMPPConnection; .

Filter looks like this:

    private class RosterPacketFilter implements PacketFilter{

        @Override
        public boolean accept(Packet packet) {
            return packet instanceof RosterPacket;
        }
    }

Listener:

private class RosterPacketListener implements PacketListener {

    @Override
    public void processPacket(Packet packet) {
        Log.d("tag", packet.toXML());
    }
}

The part that I completely don't understand is that the output for Log.d("tag", packet.toXML()); does not contain the msgblock parameter. How do I access msgblock parameter in my roster?

No need to add custom packet listener to connection object.

get all rosters from server

Roster roster = mConnection.getRoster();
// collection of RosterEntry from roster object
Collection<RosterEntry> entries= roster.getEntries();

for(RosterEntry entry : entries)
{
    Log.i("RosterName", "Name : "+ entry.getName());
    Log.i("RosterName", "Name : "+ entry.getUser());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM