Reputation: 30076
Using Smack, how I can get Nickname/Username from JID using Smake.
Note, the JID is not in my roaster.
Thanks.
Upvotes: 1
Views: 1858
Reputation: 812
we can get nick name using JID but we must add all users in VCARD
String nickname = smackHelper.getNickname(from);
public String getNickname(String jid) throws SmackInvocationException {
VCard vCard = vCardHelper.loadVCard(jid);
return vCard.getNickName();
}
public VCard loadVCard(String jid) throws SmackInvocationException {
VCard vCard = new VCard();
try {
vCard.load(con, jid);
return vCard;
} catch (Exception e) {
throw new SmackInvocationException(e);
}
}
Upvotes: 0
Reputation: 6067
May be its too late but for others who are facing this issue From smack:4.2.0
You can get all parts separately using JID.
if you have JID like abcd@xyzPc- 599
String local = XmppStringUtils.parseLocalpart(userObject.getUserId().toString());
Log.d(TAG, local); // print abcd
String domain = XmppStringUtils.parseDomain(userObject.getUserId().toString());
Log.d(TAG, domain); // print xyzPc-599
You can check code for XmppStringUtils.
Hope will help to someone...
Upvotes: 1
Reputation: 410
Use the String Utils of Smack to parse the name portion of the JID
String name = StringUtils.parseName(JID);
WHen you say it's not in your Roster, how are you being passed the JID? Are you getting it from your message?
Upvotes: 0