How to send and listen to custom xmpp presence packet with asmack the library

三世轮回 提交于 2019-12-11 03:44:03

问题


I'm struggling to listen to contacts' updating of VCard. I'm trying to do this by sending a custom presence that carries some custom information while updating VCard.from the output of the debug,I found that ,whenever such a custom presence is send,it's contact will receive the presence stanza.Unfortunately,when the contact's packetListener can not detect the incoming packet,and then all of the listener added to the connection seems have been removed, that is other packet that can be detected previously can not listened though the debug still works well. some of my code snippet just like this:

// to update VCard
 mVCard.load(mXMPPConnection);
        mVCard.setField(XmppUserInfo.tagHeadIcon, userInfo.getHeadIconUrl());
        mVCard.setField(XmppUserInfo.tagGender, userInfo.getGender());
        mVCard.setField(XmppUserInfo.tagNickname,userInfo.getNickname());
        mVCard.setField(XmppUserInfo.tagAccount, userInfo.getAccount());
        mVCard.setField(XmppUserInfo.tagSignnature, userInfo.getSignnature());
        mVCard.save(mXMPPConnection);


 // to send custom presence to subscribers to renew infomation
            Presence presence = new Presence(Type.available);
            presence.addExtension(new UserInfoExtension(userInfo));
            mXMPPConnection.sendPacket(presence);

and my Listener is like this :

//add Listener  

PacketListener packetListener = new PacketListener() {

            @Override
            public void processPacket(Packet packet) {
                if(null != packet){
                    Log.i(TAG,"UserInfo is being updated" );
                    Log.i(TAG, "the packet is " +packet.toXML());

                    }
                }
            }
        };
        xmppConnection.addPacketListener(packetListener, new PacketFilter() {

            @Override
            public boolean accept(Packet p) {
                return true;
            }
        });

but I can not say the prescen stanza in log though I can receive the presence from the output of debug. can any body help me? thanks very much.

the receieved presence is like this:

<presence id="AL4As-4" from="20298509@openfire/ad9a8862" to="20298468@openfire">
<user xmlns="kascend:video:xmpp:userinfo">
<info account="133787245" gender="f" signnature="wwwwwww" nickname="bbbb"/>
</user>
<c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.igniterealtime.org/projects/smack/" ver="O1jiM4C3yPnCFLp9hBZUn4AgVXs="/></presence>

回答1:


I'm sorry to mislead you. finally it turns out that the problem is caused by the error in my extension provider,which can bring the program into a endless loop. I fix that error ,and now it all works fine.



来源:https://stackoverflow.com/questions/14357707/how-to-send-and-listen-to-custom-xmpp-presence-packet-with-asmack-the-library

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