MohammadReza Vahedi MohammadReza Vahedi - 5 months ago 29
Android Question

I can not get nickName from users that currently added

i am new in asmack. i am writing a chat application and when i add a user by send him/her a subscription packet an he accept, i check openFire server nikename and other properties is ok for new user and mode is both.

but when i try to get friends data nickname is empty.

if i debug the code nickname receive correctly but in run mode can not?

code to receive friends :

public static void getContacts(final Context ctx)
{
try
{
try
{
Thread.sleep(1000);
}
catch(Exception ex)
{

}
Roster roster = connection.getRoster();

Collection<RosterEntry> entries = roster.getEntries();
if(globalVars.friends == null)
globalVars.friends = new ArrayList<globalVars.UserList>();
globalVars.friends.clear();

for(RosterEntry entry: entries)
{
String user = entry.getUser();
String username = user.split("@")[0];
Presence presence = roster.getPresence(entry.getUser());
int status = R.drawable.offline;
if(presence.getType().equals(Presence.Type.available))
status = R.drawable.online;
//String fromto = presence.getFrom() + " "+presence.getTo();
globalVars.UserList ul = new UserList(username, status, globalVars.smallImageAddress(ctx, username));

String wathsUp = "";

try
{
if(presence.getStatus() != null)
wathsUp = presence.getStatus();
}
catch(Exception ex)
{

}
ul.setComment(wathsUp);
ul.setFriend(true);
ul.setNikName(entry.getName());

globalVars.friends.add(ul);
}


can anyone help me?

Answer

Use vCard for setting nickname or other details of a user. Use this code for getting Vcard information from a jid

VCard mVCard = new VCard();

mVCard.load(your xmppconnection,user jid);
String name = mVCard.getNickName();