简体   繁体   中英

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.

I fixed it adding:

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

after:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM