Android基於XMPP Smack openfire 開發的聊天室(五) 【邀請、被邀請】

來源:互聯網
上載者:User

1,邀請:

很簡單的一句話,邀請的時候要傳入受邀者的JID,邀請資訊可以為空白。

 

muc.invite(userjid, "進來我們聊妹子");

 

簡單的同時我們要知道它發生了什麼,當這句話執行會向伺服器發送一段報文,如下:

<message    from='crone1@shakespeare.lit/desktop'    to='darkcave@chat.shakespeare.lit'>  <x xmlns='http://jabber.org/protocol/muc#user'>    <invite to='hecate@shakespeare.lit'>      <reason>        進來我們聊妹子      </reason>    </invite>  </x></message>

2,被邀請

被邀請呢,我們可以開個監聽吧,要不要進房間先不判斷了,我這裡如果有邀請就直接進房間。有需要的朋友可以自己琢磨:

MultiUserChat.addInvitationListener(Constants.conn,new InvitationListener() {// 對應參數:串連、 房間JID、房間名、附帶內容、密碼、訊息@Overridepublic void invitationReceived(Connection conn,String room, String inviter, String reason,String password, Message message) {Log.i(TAG, "收到來自 " + inviter + " 的聊天室邀請。邀請附帶內容:"+ reason);Intent intent = new Intent(MucService.this,ActivityMultiRoom.class);intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.putExtra("jid", room);intent.putExtra("action", "join");startActivity(intent);}});

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.