如何使用 asmack 库发送和侦听自定义 xmpp 存在数据包 [英] How to send and listen to custom xmpp presence packet with asmack the library

查看:20
本文介绍了如何使用 asmack 库发送和侦听自定义 xmpp 存在数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力听取联系人对 VCard 的更新.我试图通过在更新 VCard 时发送带有一些自定义信息的自定义状态来实现这一点.从调试的输出中,我发现,每当发送这样的自定义状态时,它的联系人都会收到状态节.不幸的是,当联系人的 packetListener 无法检测到传入的数据包时,然后所有添加到连接的侦听器似乎都已被删除,即之前可以检测到的其他数据包无法侦听,尽管调试仍然有效.我的一些代码片段就像这样:

//更新VCardMVCard.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);//向订阅者发送自定义状态以更新信息Presence 存在 = 新存在(Type.available);存在.addExtension(新用户信息扩展(用户信息));mXMPPConnection.sendPacket(存在);

我的监听器是这样的:

//添加监听器PacketListener packetListener = new PacketListener() {@覆盖公共无效过程包(包包){如果(空!= 数据包){Log.i(TAG,"用户信息正在更新");Log.i(TAG, "数据包是" +packet.toXML());}}}};xmppConnection.addPacketListener(packetListener, new PacketFilter() {@覆盖公共布尔接受(数据包 p){返回真;}});

但我不能在日志中说出 prescen 节,尽管我可以从 debug 的输出中接收到存在.有谁能够帮助我?非常感谢.

收到的存在是这样的:

<user xmlns="kascend:video:xmpp:userinfo"><info account="133787245"gender="f" signnature="wwwww"nickname="bbbb"/></用户><c xmlns="http://jabber.org/protocol/caps" hash="sha-1" node="http://www.igniterealtime.org/projects/smack/" ver="O1jiM4C3yPnCFLp9hBZUn4AgVXs="/></presence>

解决方案

很抱歉误导您.最后发现问题是我的扩展提供程序的错误导致的,这会使程序陷入死循环.我修复了那个错误,现在一切正常.

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>

解决方案

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.

这篇关于如何使用 asmack 库发送和侦听自定义 xmpp 存在数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆