管理组聊会话

使用getParticipants方法你可以获取在一个聊天会话中参与者的列表。和正常的聊天一样,你可以发送文本或数据消息给你想发的每个聊天成员,还可以使用inviteContact方法来邀请新的成员。leave方法允许你离开一个聊天室并结束会话。

 

和正常聊天一样,你可以通过实现并注册一个IChatListener来监听聊天室消息。和监听聊天消息一样,你还可以对人员加入或离开聊天室作出反应。

 

接下来的框架代码显示了实现一个聊天监听者的实现:

 

IChatListener groupChatListener = new IChatListener.Stub() {

// Fired when a one-to-one chat becomes a group chat.

public void convertedToGroupChat(String oldJid,String groupChatRoom,long groupId)

throws RemoteException {

// TODO Notify user that the conversation is now a group chat.

}

 

// Fired when a new person joins a chat room.

public void participantJoined(String groupChatRoom, String nickname)

throws RemoteException {

// TODO Notify user that a new participant has joined the conversation.

}

 

// Fired when a participant leaves a chat room.

public void participantLeft(String groupChatRoom, String nickname)

throws RemoteException {

// TODO Notify user a chat participant left.

}

 

// Fired when the group chat is closed

public void chatClosed(String groupChatRoom) throws RemoteException {

// TODO Close the chat.

}

 

public void chatRead(String arg0) throws RemoteException { }

public void newMessageReceived(String from, String body) { }

};

posted on 2009-10-06 22:20  xirihanlin  阅读(390)  评论(0编辑  收藏  举报