Hi,
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:
- Users Name
- User Id
How to fetch:
- User Full name
- Users Avatar / image
- Users email, phone, last name etc.
- Staus (available / busy / ) etc
- 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) vCard.load(connection); 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) { ex.printStackTrace(); } return vCard; } // +++++++++++++++++ Avatar +++++++++++++++++++++++++++++++++++ public static void main(String args[]) { try { XMPPConnection connection = new XMPPConnection("Your Server IP"); connection.connect(); connection.login("Your XMPP User Name", "Your Password"); //+++++++++++++++++ Roster +++++++++++++++++++++++++++++++++ Roster roster = connection.getRoster(); Collection entries = roster.getEntries(); Iterator it = entries.iterator(); while(it.hasNext()) { RosterEntry entry = (RosterEntry) it.next(); System.out.println(entry.getName() + " (" + entry.getUser() + ") ["+entry.getStatus()+ "] - [" + entry.getType() + "]"); } //+++++++++++++++++ Roster +++++++++++++++++++++++++++++++++++ getVCard(connection,"soumya_iiitc@yahoo.com"); connection.disconnect(); } catch(Exception e) { System.out.println(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