问题描述
我正在使用Smack库在Android上运行XMPP客户端。名单/消息/存在的东西运行得很好。但是,我没有找到存储其他个人资料信息的方法(用户图片,狗名,......)。
我从谷歌搜索中看到的唯一方法是使用电子名片。但它根本行不通。我尝试了以下方法:
VCard vCard = new VCard();
vCard.load(连接);
vCard.setEmailHome([email protected]);
vCard.setLastName(Scheller);
vCard.setField(blafasel,asdf);
vCard.save(连接);
然后我正在寻找一种方法来查看VCard信息。它既没有出现在iChat中也没出现在这个System.out中:
vCard.load(连接,用户);
System.out.println(user +有这个vCard:+ vCard.toXML());
所以出了什么问题,但没有迹象表明它是什么。我尝试使用google talk服务器和我自己的openfire副本,结果相同。顺便说一下,我正在使用这个版本的Smack:
我查看了Smack的来源并通过了使用调试器的重要部分,以及使用Smack调试窗口。问题出在。保存VCard确实可以正常工作,但是加载会中断。
parseIQ(XmlPullParser解析器)是PacketReader.java类的一部分,可以处理不同类型的包。它只处理具有以下命名空间的标签:
jabber:iq:auth,
jabber:iq:roster,
jabber :iq:register,
urn:ietf:params:xml:ns:xmpp-bind
它还会查看是否有任何已注册的IQProvider ProviderManager。这是我问题的根源。注册的VCards没有IQProvider。因此,无论vCard标签内的任何信息都被删除。
虽然注册这个IQProvider并不太难:
ProviderManager.getInstance()。addIQProvider(vCard,vcard-temp,new VCardProvider());
这解决了上面的小例子,用于保存我自己的vCard并再次下载。我仍然无法下载其他用户的vcards ...要仔细研究这个问题,并为这个问题打开另一个线程。
I am working on a XMPP client on Android, using the Smack library. The roster/messaging/presence stuff is running very well. However, I didn't find a way to store additional profile information (userpicture, the dogs name, ...).
The only way I see from googling is using VCards. But it simply did not work. I tried the following:
VCard vCard = new VCard();
vCard.load(connection);
vCard.setEmailHome("[email protected]");
vCard.setLastName("Scheller");
vCard.setField("blafasel", "asdf");
vCard.save(connection);
Then I was looking for a way to see that VCard information. It did neither show up in iChat nor in this System.out:
vCard.load(connection, user);
System.out.println(user + " has this vCard: " + vCard.toXML());
So anything went wrong, but theres no indication what it was. I tried this with the google talk server and my own copy of openfire with the same result. Btw, I am using this version of Smack: http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/
What am I doing wrong here? What is the correct way of storing profile related information with Smack?
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.
这篇关于如何使用Smack使用XMPP设置/获取配置文件数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!