【问题标题】:Smack 4.1.0 android Roster not displayingSmack 4.1.0 android名册不显示
【发布时间】:2015-06-06 19:03:43
【问题描述】:

我正在尝试显示所有可用的联系人,即使它没有显示

代码:

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

我将不胜感激。

【问题讨论】:

    标签: android xmpp smack asmack


    【解决方案1】:

    注意

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

    【讨论】:

      【解决方案2】:

      我修复了它添加:

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

      之后:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-03-03
        • 2015-08-04
        • 1970-01-01
        • 1970-01-01
        • 2015-04-22
        • 2015-07-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多