我正在尝试显示所有可用的联系人,即使它没有显示它
代码:
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);
}
}
输出:
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
我认为应该打印所有条目吗?但它的打印不属于它们。任何帮助?连接配置如下:
configBuilder.setDebuggerEnabled(true);
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
我将不胜感激。
答案 0 :(得分:3)
我修复了它:
if (!roster.isLoaded())
roster.reloadAndWait();
后:
Collection<RosterEntry> entries = roster.getEntries();
答案 1 :(得分:0)
关注
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());
}
}