如何使用 Smack 通过 XMPP 设置/获取配置文件数据

发布于 2024-08-13 17:51:26 字数 1076 浏览 7 评论 0原文

我正在 Android 上使用 Smack 库开发 XMPP 客户端。花名册/消息传递/状态等内容运行得很好。然而,我没有找到一种方法来存储额外的个人资料信息(用户图片、狗的名字……)。

我从谷歌搜索中看到的唯一方法是使用 VCard。但这根本行不通。我尝试了以下操作:

        VCard vCard = new VCard();
        vCard.load(connection);
        vCard.setEmailHome("[email protected]");
        vCard.setLastName("Scheller");
        vCard.setField("blafasel", "asdf");
        vCard.save(connection);

然后我正在寻找一种查看 VCard 信息的方法。它既没有出现在 iChat 中,也没有出现在这个 System.out 中:

        vCard.load(connection, user);
        System.out.println(user + " has this vCard: " + vCard.toXML());

所以出了什么问题,但没有任何迹象表明它是什么。我用 google talk 服务器和我自己的 openfire 副本进行了尝试,得到了相同的结果。顺便说一句,我正在使用这个版本的 Smack: http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/

我在这里做错了什么?使用 Smack 存储个人资料相关信息的正确方法是什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

打小就很酷 2024-08-20 17:51:26

我已经检查了 Smack 的源代码,并使用调试器以及使用 Smack 调试窗口浏览了重要部分。问题出在 Smack API。保存 VCard 确实可以按描述工作,但加载已损坏。

parseIQ(XmlPullParser parser) 是 PacketReader.java 类的一部分,处理不同类型的包。它仅处理具有以下命名空间的标签:

“jabber:iq:auth”,
"jabber:智商:名册",
"jabber:iq:注册",
"urn:ietf:params:xml:ns:xmpp-bind"

它还会查找 ProviderManager 中是否有任何已注册的 IQProvider。这就是我的问题的根源。没有注册 VCard 的 IQProvider。因此,vCard 标签内的任何信息都会被删除。

不过,注册这个 IQProvider 并不太难:

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

这解决了我上面保存我自己的 vCard 并再次下载的小例子。我在下载其他用户电子名片时仍然遇到问题...要仔细研究一下这个问题,也许会为该问题打开另一个线程。

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.

可遇━不可求 2024-08-20 17:51:26

您可以使用以下代码来获取信息。

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

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"));
但可醉心 2024-08-20 17:51:26

首先尝试为该用户与另一个客户端设置 vCard,然后看看这会如何改变您的结果。为了进一步诊断,您需要在 Smack 中打开协议调试(在台式机上使用“-Dsmack.debugEnabled=true”),并在此处发布相关位。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文