Exemplo n.º 1
0
  public static void main(String[] args) {
    SmackConfiguration.DEBUG = true;
    SmackConfiguration.setDefaultPacketReplyTimeout(10 * 1000);

    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
    configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    configBuilder.setUsernameAndPassword("registeruser2", "123456");

    configBuilder.setServiceName("ejabberddemo.com");
    configBuilder.setDebuggerEnabled(true).build();

    // 必须在用户状态为离线状态
    configBuilder.setSendPresence(false);

    AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
    try {
      connection.connect();
    } catch (SmackException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } catch (XMPPException e) {
      e.printStackTrace();
    }

    // FIXME
    OfflineMessageManager offlineManager = new OfflineMessageManager(connection);

    try {
      connection.login();
    } catch (XMPPException e) {
      e.printStackTrace();
    } catch (SmackException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }

    try {
      System.out.println(offlineManager.supportsFlexibleRetrieval());
      System.out.println(offlineManager.getMessageCount());
    } catch (SmackException.NoResponseException e) {
      e.printStackTrace();
    } catch (XMPPException.XMPPErrorException e) {
      e.printStackTrace();
    } catch (SmackException.NotConnectedException e) {
      e.printStackTrace();
    }
    // 上线
    Presence presence = new Presence(Presence.Type.available);
    try {
      connection.sendPacket(presence);
    } catch (SmackException.NotConnectedException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
 public void removeFriend(String username) {
   Roster roster = jc.getConnection().getRoster();
   RosterEntry entry = roster.getEntry(username);
   try {
     jc.getConnection().getRoster().removeEntry(entry);
   } catch (SmackException.NotLoggedInException e) {
     e.printStackTrace();
   } catch (SmackException.NoResponseException e) {
     e.printStackTrace();
   } catch (XMPPException.XMPPErrorException e) {
     e.printStackTrace();
   } catch (SmackException.NotConnectedException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 3
0
  public void addFriend(String username, String nickname) {
    Roster roster = jc.getConnection().getRoster();
    try {

      roster.createEntry(username, nickname, null);
      Log.i("AddFriend:", username);
    } catch (SmackException.NotLoggedInException e) {
      e.printStackTrace();
    } catch (SmackException.NoResponseException e) {
      e.printStackTrace();
    } catch (XMPPException.XMPPErrorException e) {
      e.printStackTrace();
    } catch (SmackException.NotConnectedException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  private Bitmap loadProfileImageWithVCard(String username) {
    Bitmap bitmap = null;
    Log.e(TAG, "Get pic from server");
    VCard vCard = new VCard();
    try {
      vCard.load(JabberConnection.getInstance().getConnection(), username + "@pc-pc");
      byte[] bytes = vCard.getAvatar();
      bitmap = BitmapUtil.getBitmapFromBytes(bytes);

    } catch (SmackException.NoResponseException e) {
      e.printStackTrace();
    } catch (XMPPException.XMPPErrorException e) {
      e.printStackTrace();
    } catch (SmackException.NotConnectedException e) {
      e.printStackTrace();
    }
    return bitmap;
  }