免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

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

這里寫完,最基本的IM功能也就完了,

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

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

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

包括上線,隱身,對某人隱身,對某人上線

  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. 修改用戶頭像

有點麻煩,主要是讀入圖片文件,編碼,傳輸之

  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. 補充,用戶狀態(tài)的監(jiān)聽

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

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

聯(lián)系客服