How to set/get profile data with XMPP using Smack

12,654

Solution 1

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.

Solution 2

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"));

Solution 3

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.

Share:
12,654
Ulrich Scheller
Author by

Ulrich Scheller

I am a technical manager and software developer specialized on mobile devices with Android and iOS. My mobile development experience started with the Android SDK 1.0 and I have been working in this field ever since. During the last years I helped building up mobile development teams and bringing them up to speed. We developed and maintained several applications for nearly 10 million active users (mostly in the german market). If you are looking for a development lead, an experienced developer, or someone to successfully finish a project for you, please contact me at [email protected]. I live in Munich and I am available for contract work.

Updated on June 08, 2022

Comments

  • Ulrich Scheller
    Ulrich Scheller about 2 years

    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?