Search code examples
androidxmppsmackasmack

Smack 4.1.0 android Roster not displaying


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.


Solution

  • I fixed it adding:

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

    after:

    Collection<RosterEntry> entries = roster.getEntries();