How to set/get profile data with XMPP using Smack

我是研究僧i 提交于 2019-12-04 09:45:38

I have checked out the source of Smack and went through the important parts with a debugger, as well as using the Smack Debug Window. The problem is inside the VCard implementation of the Smack API. Saving a VCard does work as described, however the loading is broken.

parseIQ(XmlPullParser parser) is part of the PacketReader.java class and handles different types of packages. It only handles tags with the following namespaces:

"jabber:iq:auth", "jabber:iq:roster", "jabber:iq:register", "urn:ietf:params:xml:ns:xmpp-bind"

It also looks if there is any registered IQProvider in the ProviderManager. And this is the root of my problem. There is no IQProvider for VCards registered. So whatever information is inside of the vCard tag simply gets dropped.

It is not too hard to register this IQProvider though:

    ProviderManager.getInstance().addIQProvider("vCard", "vcard-temp", new VCardProvider());

This solved my little example above for saving my own vCard and downloading it again. I am still having trouble with downloading other users vcards... Gonna have a closer look into this and maybe open up another thread for that issue.

Pujan Srivastava

You can use the following code to get info.

VCard card = new VCard();
card.load(connection, "user@fqdn");
System.out.println("Voice: "+card.getPhoneHome("VOICE"));

Try setting a vCard for that user with another client first, and see how that changes your results. In order to diagnose further, you'll need to turn on protocol debugging in Smack (use "-Dsmack.debugEnabled=true" on a desktop machine), and post the relevant bits here.

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