Search code examples
smack

How to get a BareJid in smack 4.2.0


I used Roster to create Roster Entry by Roster's method createEntry(BareJid user, String name, String[] groups),but I don't know how to get a BareJid. Anybody could help me?Here are my code,my userJid is a String:

Roster roster = XmppConnectionManager.getInstance().getRoster();
        if (roster != null) {
            try {
//                String[] jids = userJid.split("@");
                roster.createEntry(userJid, nickname, null);
            } catch (SmackException.NotLoggedInException e) {
                e.printStackTrace();
            } catch (SmackException.NoResponseException e) {
                e.printStackTrace();
            } catch (SmackException.NotConnectedException e) {
                e.printStackTrace();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } else {
            Log.w(TAG,"roster is null");
        }

Solution

  • I just found it by Google, there is a JID helper class JidCreate:

    JidCreate.bareFrom(userJid)