欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
XMPP——Smack[4]狀態(tài),心情,頭像更改

這里寫(xiě)完,最基本的IM功能也就完了,

還剩下個(gè)發(fā)送接收文件,離線(xiàn)消息擴展等等

呵呵,三天時(shí)間,看的不是很深入,歡迎大家補充呀

1. 修改自身狀態(tài)

包括上線(xiàn),隱身,對某人隱身,對某人上線(xiàn)

  1. public static void updateStateToAvailable(XMPPConnection connection)
  2. {
  3. Presence presence = new Presence(Presence.Type.available);
  4. connection.sendPacket(presence);
  5. }
  6. public static void updateStateToUnAvailable(XMPPConnection connection)
  7. {
  8. Presence presence = new Presence(Presence.Type.unavailable);
  9. connection.sendPacket(presence);
  10. }
  11. public static void updateStateToUnAvailableToSomeone(XMPPConnection connection,String userName)
  12. {
  13. Presence presence = new Presence(Presence.Type.unavailable);
  14. presence.setTo(userName);
  15. connection.sendPacket(presence);
  16. }
  17. public static void updateStateToAvailableToSomeone(XMPPConnection connection,String userName)
  18. {
  19. Presence presence = new Presence(Presence.Type.available);
  20. presence.setTo(userName);
  21. connection.sendPacket(presence);
  22. }

2. 心情修改

  1. /**
  2. * 修改心情
  3. * @param connection
  4. * @param status
  5. */
  6. public static void changeStateMessage(XMPPConnection connection,String status)
  7. {
  8. Presence presence = new Presence(Presence.Type.available);
  9. presence.setStatus(status);
  10. connection.sendPacket(presence);
  11. }

3. 修改用戶(hù)頭像

有點(diǎn)麻煩,主要是讀入圖片文件,編碼,傳輸之

  1. public static void changeImage(XMPPConnection connection,File f) throws XMPPException, IOException
  2. {
  3. VCard vcard = new VCard();
  4. vcard.load(connection);
  5. byte[] bytes;
  6. bytes = getFileBytes(f);
  7. String encodedImage = StringUtils.encodeBase64(bytes);
  8. vcard.setAvatar(bytes, encodedImage);
  9. vcard.setEncodedImage(encodedImage);
  10. vcard.setField("PHOTO", "<TYPE>image/jpg</TYPE><BINVAL>"
  11. + encodedImage + "</BINVAL>", true);
  12. ByteArrayInputStream bais = new ByteArrayInputStream(
  13. vcard.getAvatar());
  14. Image image = ImageIO.read(bais);
  15. ImageIcon ic = new ImageIcon(image);
  16. vcard.save(connection);
  17. }
  18. private static byte[] getFileBytes(File file) throws IOException {
  19. BufferedInputStream bis = null;
  20. try {
  21. bis = new BufferedInputStream(new FileInputStream(file));
  22. int bytes = (int) file.length();
  23. byte[] buffer = new byte[bytes];
  24. int readBytes = bis.read(buffer);
  25. if (readBytes != buffer.length) {
  26. throw new IOException("Entire file not read");
  27. }
  28. return buffer;
  29. } finally {
  30. if (bis != null) {
  31. bis.close();
  32. }
  33. }
  34. }

4. 補充,用戶(hù)狀態(tài)的監聽(tīng)

即對方改變頭像,狀態(tài),心情時(shí),更新自己用戶(hù)列表,其實(shí)這里已經(jīng)有smack實(shí)現的監聽(tīng)器

  1. final Roster roster = Client.getRoster();
  2. roster.addRosterListener(
  3. new RosterListener() {
  4. @Override
  5. public void entriesAdded(Collection<String> arg0) {
  6. // TODO Auto-generated method stub
  7. System.out.println("--------EE:"+"entriesAdded");
  8. }
  9. @Override
  10. public void entriesDeleted(Collection<String> arg0) {
  11. // TODO Auto-generated method stub
  12. System.out.println("--------EE:"+"entriesDeleted");
  13. }
  14. @Override
  15. public void entriesUpdated(Collection<String> arg0) {
  16. // TODO Auto-generated method stub
  17. System.out.println("--------EE:"+"entriesUpdated");
  18. }
  19. @Override
  20. public void presenceChanged(Presence arg0) {
  21. // TODO Auto-generated method stub
  22. System.out.println("--------EE:"+"presenceChanged");
  23. }
  24. });

下一篇主要是文件傳輸和接收

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
基于xmpp openfire smack開(kāi)發(fā)之smack類(lèi)庫介紹和使用[2]
java實(shí)現簡(jiǎn)單XMPP發(fā)送消息和文件的簡(jiǎn)單例子
基于XMPP協(xié)議的Android IM研究
SmackAPI中文版 Smack幫助文檔中文版
Android客戶(hù)端基于XMPP的IM(openfire+asmack)的聊天工具之環(huán)境搭建及與服務(wù)器建立連接(一)
一個(gè)gtalk的robot的簡(jiǎn)單實(shí)現
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久