为什么我总是得到存在类型不可用?

时间:2013-07-19 11:42:18

标签: android

我开发了简单的聊天应用程序,其中使用了asmack lib和openfire服务器。 但是当我使用相同的方式开始聊天时,我总是无法获得状态,因为该用户在openfire服务器上可用。

尝试了各种各样的东西,为talk.google.com服务器测试了相同的代码,它的效果非常好。我在这里设置用户的状态 -

                  Presence presence  = new Presence(Presence.Type.available); ; 
                  presence.setStatus("Online, Programmatically!");
                  presence.setPriority(24);
                  presence.setMode(Presence.Mode.available);
                  connection.sendPacket(presence);
                  try {
                    Thread.sleep(10000);
                  } catch (InterruptedException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                  }

当我显示名单条目时,我的状态为空,状态类型不可用,我不知道为什么会发生,尝试了各种各样的事情。我正在同一台机器上的两个不同的模拟器上测试我的代码。它是否应该相同?

以下是显示名单条目和在场类型的代码

                   Roster roster = connection.getRoster();
                  Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
                  roster.addRosterListener(new RosterListener() {
                      // Ignored events public void entriesAdded(Collection<String> addresses) {}
                      public void entriesDeleted(Collection<String> addresses) {}
                      public void entriesUpdated(Collection<String> addresses) {}
                      public void presenceChanged(Presence presence) {
                          System.out.println("Presence changed: " + presence.getFrom() + " " + presence);
                      }
                      @Override
                      public void entriesAdded(Collection<String> arg0) {
                          // TODO Auto-generated method stub
                      }
                  });
                  try { Thread.sleep(5000); } catch (InterruptedException e) { }
                  Collection<RosterEntry> entries = roster.getEntries();                
                  for (RosterEntry entry : entries) {                           
                      Presence subscribed = new Presence(Presence.Type.subscribed); 
                      subscribed.setTo(entry.getUser()); 
                      connection.sendPacket(subscribed);

                      Log.d("JWP", "RosterEntry " + entry);
                      Log.d("JWP", "User: " + entry.getUser());
                      Log.d("JWP", "Name: " + entry.getName());
                      Log.d("JWP", "Status: " + entry.getStatus());
                      Log.d("JWP", "Type: " + entry.getType());               
                      Presence entryPresence = roster.getPresence(entry.getUser());
                      Log.d("JWP", "Presence Status: "+ entryPresence.getMode());
                      Log.d("JWP", "Presence Type: " + entryPresence.getType());

                      Presence.Type type = entryPresence.getType();
                      if (type == Presence.Type.available){
                          Log.d("JWP", "Presence AVIALABLE");
                          Log.d("JWP", "Presence : " + entryPresence);
                      }
                  }

0 个答案:

没有答案