powered by Jive Software

How to display Avatar Imgaes


I am using the below code to fetch contacts / rodters / buddylist from my Openfire accoount and i am getting this OK. I am now able to print the following information mentioned below but need to help on some attributes.

Able to fetch:

  1. Users Name
  2. User Id

How to fetch:

  1. User Full name
  2. Users Avatar / image
  3. Users email, phone, last name etc.
  4. Staus (available / busy / ) etc
  5. Users status message.

I am using this code below.

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import javax.imageio.ImageIO;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.smack.*;

public class XMPPTest {
    //+++++++++++++++++ Avatar +++++++++++++++++++++++++++++++++++

    public static VCard getVCard(XMPPConnection connection, String myJID) {
        VCard vCard = new VCard();
        try {                  
            if (myJID == null)
            else vCard.load(connection, myJID);
            // If VCard is loaded, then save the avatar to the personal folder.
            byte[] bytes = vCard.getAvatar();
            try {
                InputStream in = new ByteArrayInputStream(bytes);
                BufferedImage bi = javax.imageio.ImageIO.read(in);
                File outputfile = new File("C://Avatar.jpg");
                ImageIO.write(bi, "jpg", outputfile);
                catch (IOException e){}
        } catch (XMPPException ex) {
        return vCard;
    //    +++++++++++++++++ Avatar +++++++++++++++++++++++++++++++++++
    public static void main(String args[])
            XMPPConnection connection = new XMPPConnection("Your Server IP");
            connection.login("Your XMPP User Name", "Your Password");
            //+++++++++++++++++ Roster +++++++++++++++++++++++++++++++++
            Roster roster = connection.getRoster();
            Collection entries = roster.getEntries();
            Iterator it = entries.iterator();               
                RosterEntry entry  = (RosterEntry) it.next();
                System.out.println(entry.getName() + " (" + entry.getUser() + ")  ["+entry.getStatus()+ "] - [" + entry.getType() + "]");
            //+++++++++++++++++ Roster +++++++++++++++++++++++++++++++++++   
        catch(Exception e)



I am getting this out as below:

Rahul Paul (paul.rahul\40gmail.com@gtalk.zenon173) [null] - [to]
Anirban Banerjee (banerjee.anirban\40gmail.com@gtalk.zenon173) [null] - [to]
Ritesh Saxena (ritsaxena\40gmail.com@gtalk.zenon173) [null] - [to]
Amol in Bangalore (codergeek82\40gmail.com@gtalk.zenon173) [null] - [to]


How can get this users Avatar Image, Status, S
tatus text etc??

Thanks In Advance

Soumyadipta De


I am getting Avatar image only when trying with some XMPP user. means i have setuped Openfire at domainname “testxmpp”. So when i am doing

getVCard(connection,“user1@textxmpp”); i am geting the image properly. but when i am trying to fetch Vcard for msn,yahoo or gtalk user it fails and i get the errors mentioned below.

Timeout getting VCard information: request-timeout(408) Timeout getting VCard information
at org.jivesoftware.smackx.packet.VCard.doLoad(VCard.java:552)
at org.jivesoftware.smackx.packet.VCard.load(VCard.java:537)
at IMClient.getVCard(IMClient.java:28)
at IMClient.main(IMClient.java:142)


What i am doping wrong or any idea on what i have to change in my code?


I am getting this rosters as mentioned below so whta i have to write to fetch VCard for user name “Rahul Paul”.(paul.rahul\40gmail.com@gtalk.zenon173)

Rahul Paul (paul.rahul\40gmail.com@gtalk.zenon173) [null] - [to]
Anirban Banerjee (banerjee.anirban\40gmail.com@gtalk.zenon173) [null] - [to]
Ritesh Saxena (ritsaxena\40gmail.com@gtalk.zenon173) [null] - [to]
Amol in Bangalore (codergeek82\40gmail.com@gtalk.zenon173) [null] - [to]