我是阿斯马克的新人。我正在编写一个聊天应用程序,当我通过向他/她发送订阅数据包并他接受来添加用户时,我检查 openFire 服务器 nikename 和其他属性对于新用户来说是否正常,并且模式都是两者。
但是当我尝试获取好友数据时,昵称为空。
如果我调试代码昵称正确接收但在运行模式下不能?
接收好友的代码:
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);
}
谁能帮我吗?
最佳答案
使用 vCard 设置用户的昵称或其他详细信息。 使用此代码从 jid 获取 Vcard 信息
VCard mVCard = new VCard();
mVCard.load(your xmppconnection,user jid);
String name = mVCard.getNickName();
关于android - 我无法从当前添加的用户获取昵称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24854172/