kobbycoder
kobbycoder

Reputation: 682

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.

Upvotes: 2

Views: 1348

Answers (2)

raditya gumay
raditya gumay

Reputation: 3011

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());
    }
}

Upvotes: 0

kobbycoder
kobbycoder

Reputation: 682

I fixed it adding:

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

after:

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

Upvotes: 3

Related Questions