Android基于XMPP Smack openfire 开发的聊天室(五) 【邀请、被邀请】

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、房间名、附带内容、密码、消息
					@Override
					public 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);
					}
				});


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值