你好,你需要自定义一个 AVIMConversationEventHandler,然后设置消息 handler:
AVIMMessageManager.setConversationEventHandler(new CustomConversationEventHandler());
在 CustomConversationEventHandler 类声明里,重写 onOfflineMessagesUnread() 方法。
public class CustomConversationEventHandler extends AVIMConversationEventHandler {
@Override
public void onOfflineMessagesUnread(AVIMClient client, AVIMConversation conversation, int unreadCount) {
super.onOfflineMessagesUnread(client, conversation, unreadCount);
}
@Override
public void onMemberLeft(AVIMClient client, AVIMConversation conversation, List<String> members,
String kickedBy) {
// 有其他成员离开时,执行此处逻辑
}
@Override
public void onMemberJoined(AVIMClient client, AVIMConversation conversation,
List<String> members, String invitedBy) {
// 手机屏幕上会显示一小段文字:Tom 加入到 551260efe4b01608686c3e0f ;操作者为:Tom
Toast.makeText(AVOSCloud.applicationContext,
members + "加入到" + conversation.getConversationId() + ";操作者为: "
+ invitedBy, Toast.LENGTH_SHORT).show();
}
@Override
public void onKicked(AVIMClient client, AVIMConversation conversation, String kickedBy) {
// 当前 ClientId(Bob) 被踢出对话,执行此处逻辑
}
@Override
public void onInvited(AVIMClient client, AVIMConversation conversation, String invitedBy) {
// 当前 ClientId(Bob) 被邀请到对话,执行此处逻辑
}
}
参考: https://leancloud.cn/docs/realtime_guide-android.html#自身主动加入9