是否可以在两个模拟器上测试聊天应用程序?

时间:2013-07-19 10:50:47

标签: android

我使用asmack lib和openfire创建了一个聊天简单聊天应用程序,但是当我在模拟器上测试它时,我总是得到状态不可用,因为我的openfire服务器上有相同的用户。

我已经测试了我的talk.google.com服务器代码,它无缝地工作,但是当我用开放式测试时,我总是得到不可用的状态。我尝试了各种各样的事情,比如在openfire设置中设置订阅选项。

我已经编写了以下用于设置在线状态的代码:

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 个答案:

没有答案