How do I update account attributes after the account is created

I see create account in AccountManager updates attributes, but how can I add or update additional attributes to the account after it is created?

Look at the org.jivesoftware.smack.packet.Registration class.

eg:

// Conn is an XMPPConnection instance
//
import java.util.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.Registration;
import org.jivesoftware.smack.util.StringUtils;
// .... // get the exisiting account attributes
AccountManager am=Conn.getAccountManager();
Iterator i=am.getAccountAttributes();
// create a hashmap for the attributes
HashMap map=new HashMap();
// copy existing attributes into map
while(i.hasNext()){
  String name=(String) i.next();
   map.put(name,am.getAccountAttribute(name));
}
// alter an attribute in the map
// you''d normally check it exists first
map.put("email","mynewemaill@address.com");
// create a registration packet
Registraion reg=new Registration();
reg.setType(IQ.Type.SET); // we''re setting the attributes
reg.setFrom(Conn.getUser()); // set the from address to be from this user
reg.setUsername(StringUtils.parseBareAddress(Conn.getUser())); reg.setTo(Conn.getHost()); // set to address to the user''s server
reg.setAttributes(map); // set the attributes
Conn.sendPacket(reg); // send the packet

You need to have an try catch block to catch any exeptions and be aware that the code will block while its retrieving and sending data so don’‘t use it inside the Event Dispatch Thread. You’'d also normally want to listen for a reply when sending the reg packet ( create a collector that listens for a packet with the same id as the reg packet).

HTH,

Pheet

Message was edited by:

Pheet