asmack : Receiving custom IQ messages in PacketListener

不羁的心 提交于 2019-12-23 04:42:10

问题


I am using asmack library for an XMPP chat application. I have some issues in receiving few custom IQ packets.

This is my PacketListener code :

PacketTypeFilter filter = new PacketTypeFilter(Packet.class);
connection.addPacketListener(new PacketListener() {
    @Override
    public void processPacket(Packet packet) {
        Log.i("PacketListener : ", "Received Packet in General : "
                + packet.toXML());
    }
}, filter);

It receives some IQ packets, but doesn't receive some other IQ packets. But, the asmack library is able to receive and print all the IQ packets in the Logcat under the Tag "SMACK" and a prefix as "RCV (1): ".

Any suggestions to receive all the IQ packets inside PacketListener ?
Please, let me know if something is not clear in the question by adding comments.


回答1:


You need to add a provider.

For example

myProvider yourProvider = new myProvider();
ProviderManager.getInstance().addIQProvider("jingle","urn:xmpp:jingle:1",yourProvider);

So asmack listens for those type of packets. yourProvider is your implementation of an IQProvider

e.g

public class myProvider implements IQProvider {

@Override
public IQ parseIQ(XmlPullParser parser) throws Exception {
    //Parse the incomming call data

}

Then you create your own implementation of the IQ class.

public class YourIQ extends IQ {}

And finally

theConnectionObject.addPacketListener(new IQPacketListener()
            , new PacketTypeFilter(YourIQ .class) {
        @Override
        public boolean accept(Packet packet) {//Do your stuff}



回答2:


Finally, I could able to receive the jingle IQ packets using this code

https://github.com/bejayoharen/java-bells/tree/master/src/net/java/sip/communicator/impl/protocol/jabber/extensions/jingle



来源:https://stackoverflow.com/questions/25776461/asmack-receiving-custom-iq-messages-in-packetlistener

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!