Smack 4.1.0 android Roster not displaying
Asked Answered
R

2

2

I am trying to display all available contacts even though it is not displaying it

Code:

Roster roster = Roster.getInstanceFor(connection);
Collection<RosterEntry> entries = roster.getEntries();
System.out.println("ENTRIEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEESS");
int roster_counter = 0;
for (RosterEntry entry : entries) {
     roster_counter++;
     try {
         System.out.println("Here is Roster " + Integer.toString(roster_counter) + ": " + entry);
     }catch (Exception e){
           System.out.println("2222222222222222222222");
           System.out.println(e);
     }
}

output:

04-01 18:07:41.535    2756-2776/com.example.example I/System.out﹕ ##########################################################
04-01 18:07:41.535    2756-2776/com.example.example I/System.out﹕ ====================================================
04-01 18:07:41.537    2756-2776/com.example.example I/System.out﹕ PRESSSSSEEEEEEN STABLISHEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEED

I think it should print all entries right? but its printing non of them. any help? The connection configuration is this:

configBuilder.setDebuggerEnabled(true);
                configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);

I would appreciate any help.

Royalroyalist answered 1/4, 2015 at 23:22 Comment(0)
R
3

I fixed it adding:

if (!roster.isLoaded()) 
    roster.reloadAndWait();

after:

Collection<RosterEntry> entries = roster.getEntries();
Royalroyalist answered 2/4, 2015 at 5:3 Comment(0)
G
0

for attention

public void getRoaster(final Callback<Collection<RosterEntry>> callback) {
    final Roster roster = Roster.getInstanceFor(connection);
    if (!roster.isLoaded())
    try {
        roster.reloadAndWait();
    } catch (SmackException.NotLoggedInException | SmackException.NotConnectedException | InterruptedException e) {
        e.printStackTrace();
    }

    Collection<RosterEntry> entries = roster.getEntries();
    for (RosterEntry entry : entries) {
        android.util.Log.d(AppConstant.PUBLIC_TAG, entry.getName());
    }
}
Glendaglenden answered 25/10, 2015 at 5:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.