SDK使用步骤
String apiUrl = ""; // SDK的API接口地址。如:http://xxx:10000
String wsUrl = ""; // SDK的Websocket地址。如:ws://xxx:17778
String storageDir = ""; // 数据存储路径。如:context.getCacheDir().getAbsolutePath()
int logLevel = 6; // 日志等级
String objectStorage = "cos"; // 图片上传服务器如 腾讯cos
boolean result = OpenIMClient.getInstance().initSDK(apiUrl, wsUrl, storageDir, logLevel, objectStorage,
new OnConnListener() {
@Override
public void onConnectFailed(long code, String error) {
// 连接服务器失败,可以提示用户当前网络连接不可用
}
@Override
public void onConnectSuccess() {
// 已经成功连接到服务器
}
@Override
public void onConnecting() {
// 正在连接到服务器,适合在 UI 上展示“正在连接”状态。
}
@Override
public void onKickedOffline() {
// 当前用户被踢下线,此时可以 UI 提示用户“您已经在其他端登录了当前账号,是否重新登录?”
}
@Override
public void onUserTokenExpired() {
// 登录票据已经过期,请使用新签发的 UserSig 进行登录。
}
});
// 用户资料变更监听
OpenIMClient.getInstance().userInfoManager.setOnUserListener(new OnUserListener() {
@Override
public void onSelfInfoUpdated(UserInfo info) {
// 当前登录用户资料变更回调
}
});
// 收到新消息,已读回执,消息撤回监听。
OpenIMClient.getInstance().messageManager.setAdvancedMsgListener(new OnAdvanceMsgListener() {
@Override
public void onRecvNewMessage(Message msg) {
// 收到新消息,界面添加新消息
}
@Override
public void onRecvC2CReadReceipt(List<ReadReceiptInfo> list) {
// 消息被阅读回执,将消息标记为已读
}
@Override
public void onRecvMessageRevoked(String msgId) {
// 消息成功撤回,从界面移除消息
}
@Override
public void onRecvGroupMessageReadReceipt(List<ReadReceiptInfo> list) {
// 消息被阅读回执,将消息标记为已读
}
});
// 好关系发生变化监听
OpenIMClient.getInstance().friendshipManager.setOnFriendshipListener(new OnFriendshipListener() {
@Override
public void onBlacklistAdded(BlacklistInfo u) {
// 拉入黑名单
}
@Override
public void onBlacklistDeleted(BlacklistInfo u) {
// 从黑名单删除
}
@Override
public void onFriendApplicationAccepted(FriendApplicationInfo u) {
// 发出或收到的好友申请已同意
}
@Override
public void onFriendApplicationAdded(FriendApplicationInfo u) {
// 发出或收到的好友申请被添加
}
@Override
public void onFriendApplicationDeleted(FriendApplicationInfo u) {
// 发出或收到的好友申请被删除
}
@Override
public void onFriendApplicationRejected(FriendApplicationInfo u) {
// 发出或收到的好友申请被拒绝
}
@Override
public void onFriendInfoChanged(FriendInfo u) {
// 朋友的资料发生变化
}
@Override
public void onFriendAdded(FriendInfo u) {
// 好友被添加
}
@Override
public void onFriendDeleted(FriendInfo u) {
// 好友被删除
}
});
// 会话新增或改变监听
OpenIMClient.getInstance().conversationManager.setOnConversationListener(new OnConversationListener() {
@Override
public void onConversationChanged(List<ConversationInfo> list) {
// 已添加的会话发送改变
}
@Override
public void onNewConversation(List<ConversationInfo> list) {
// 新增会话
}
@Override
public void onSyncServerFailed() {
}
@Override
public void onSyncServerFinish() {
}
@Override
public void onSyncServerStart() {
}
@Override
public void onTotalUnreadMessageCountChanged(int i) {
// 未读消息数发送变化
}
});
// 群组关系发生改变监听
OpenIMClient.getInstance().groupManager.setOnGroupListener(new OnGroupListener() {
@Override
public void onGroupApplicationAccepted(GroupApplicationInfo info) {
// 发出或收到的组申请被接受
}
@Override
public void onGroupApplicationAdded(GroupApplicationInfo info) {
// 发出或收到的组申请有新增
}
@Override
public void onGroupApplicationDeleted(GroupApplicationInfo info) {
// 发出或收到的组申请被删除
}
@Override
public void onGroupApplicationRejected(GroupApplicationInfo info) {
// 发出或收到的组申请被拒绝
}
@Override
public void onGroupInfoChanged(GroupInfo info) {
// 组资料变更
}
@Override
public void onGroupMemberAdded(GroupMembersInfo info) {
// 组成员进入
}
@Override
public void onGroupMemberDeleted(GroupMembersInfo info) {
// 组成员退出
}
@Override
public void onGroupMemberInfoChanged(GroupMembersInfo info) {
// 组成员信息发生变化
}
@Override
public void onJoinedGroupAdded(GroupInfo info) {
// 创建群: 初始成员收到;邀请进群:被邀请者收到
}
@Override
public void onJoinedGroupDeleted(GroupInfo info) {
// 退出群:退出者收到;踢出群:被踢者收到
}
});
String uid = ""; // uid来自于自身业务服务器
String token = ""; // token需要业务服务器根据secret向OpenIM服务端交换获取
OpenIMClient.getInstance().login(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, uid, token);
OpenIMClient.getInstance().logout(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
});
List<String> uidList = new ArrayList<>(); // 用户ID集合
OpenIMClient.getInstance().userInfoManager.getUsersInfo(new OnBase<List<UserInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<UserInfo> data) {
}
}, uidList);
OpenIMClient.getInstance().userInfoManager.getSelfUserInfo(new OnBase<UserInfo>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(UserInfo data) {
// 返回当前登录用户的资料
}
});
会触发当用户的onSelfInfoUpdated回调,以及好友的onFriendInfoChanged、onConversationChanged回调。
String nickname = ""; // 用户昵称
String faceURL = ""; // 用户头像
int gender = 0; // 性别:1男,0女
int appMangerLevel = 1;
String phoneNumber = ""; // 手机号
long birth = 0L; // 出生日期
String email = ""; //邮箱
String ex = ""; // 额外信息
OpenIMClient.getInstance().userInfoManager.setSelfInfo(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, nickname, faceURL, gender, appMangerLevel, phoneNumber, birth, email, ex);
OpenIMClient.getInstance().conversationManager.getAllConversationList(new OnBase<List<ConversationInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<ConversationInfo> data) {
}
});
long offset = 0; // 偏移量,如:第1页,offset:0,count:20;第2页:offset:20;
long count = 0; // 每页数量
OpenIMClient.getInstance().conversationManager.getConversationListSplit(new OnBase<List<ConversationInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<ConversationInfo> data) {
}
}, count, offset);
String sourceID = ""; // 如果是单聊值传userID,如果是群聊groupID
int sessionType = 1; // 如果是单聊值传1,如果是群聊值传2
OpenIMClient.getInstance().conversationManager.getOneConversation(new OnBase<ConversationInfo>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(ConversationInfo data) {
}
}, sourceID, sessionType);
List<String> conversationIDList = new ArrayList<>(); // 会话ID集合
OpenIMClient.getInstance().conversationManager.getMultipleConversation(new OnBase<List<ConversationInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<ConversationInfo> data) {
}
}, conversationIDList);
会触onTotalUnreadMessageCountChanged回调
String conversationID = ""; // 会话id
OpenIMClient.getInstance().conversationManager.deleteConversation(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, conversationID);
会触onConversationChanged回调
String conversationID = ""; // 会话id
String draftText = ""; // 草稿
OpenIMClient.getInstance().conversationManager.setConversationDraft(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, conversationID, draftText);
会触onConversationChanged回调
String conversationID = ""; // 会话id
boolean isPinned = true; // true:置顶;false:取消置顶
OpenIMClient.getInstance().conversationManager.pinConversation(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, conversationID, isPinned);
会触onConversationChanged、onTotalUnreadMessageCountChanged回调
String groupID = ""; // 组ID
OpenIMClient.getInstance().conversationManager.markGroupMessageHasRead(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID);
OpenIMClient.getInstance().conversationManager.getTotalUnreadMsgCount(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
});
String sourceID = ""; // 如果是单聊值传userID,如果是群聊groupID
int sessionType = 1; // 如果是单聊值传1,如果是群聊值传2
OpenIMClient.getInstance().conversationManager.getConversationIDBySessionType(sourceID, sessionType);
List<String> conversationIDs = new ArrayList<>(); // 会话id列表
long status = 0; // 1:不接受消息;2:接受在线消息不接受离线消息;0:正常
OpenIMClient.getInstance().conversationManager.setConversationRecvMessageOpt(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, conversationIDs, status);
List<String> conversationIDs = new ArrayList<>(); // 会话id列表
OpenIMClient.getInstance().conversationManager.getConversationRecvMessageOpt(new OnBase<List<NotDisturbInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<NotDisturbInfo> data) {
}
}, conversationIDs);
String conversationID; //会话ID
boolean isPrivate = true; // 开启
OpenIMClient.getInstance().conversationManager.setOneConversationPrivateChat(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, conversationID, isPrivate);
String conversationID; //会话ID
OpenIMClient.getInstance().conversationManager.deleteConversationFromLocalAndSvr(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, conversationID);
OpenIMClient.getInstance().conversationManager.deleteAllConversationFromLocal(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
});
String conversationID; //会话ID
OpenIMClient.getInstance().conversationManager.resetConversationGroupAtType(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, conversationID);
OpenIMClient.getInstance().conversationManager.getAtAllTag();
OpenIMClient.getInstance().conversationManager.simpleComparator();
List<String> uidList = new ArrayList<>(); // userId列表
OpenIMClient.getInstance().friendshipManager.getFriendsInfo(new OnBase<List<UserInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<UserInfo> data) {
}
}, uidList);
主动申请者收到OnFriendApplicationAdded
被添加者收到OnFriendApplicationAdded
String uid = ""; // 用户id
String reqMessage = ""; // 发起好友申请的描述信息
OpenIMClient.getInstance().friendshipManager.addFriend(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, uid, reqMessage);
List<String> uidList = new ArrayList<>(); // userId列表
OpenIMClient.getInstance().friendshipManager.checkFriend(new OnBase<List<FriendshipInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<FriendshipInfo> data) {
}
}, uidList);
操作者收到OnFriendDeleted
String uid = ""; // 用户id
OpenIMClient.getInstance().friendshipManager.deleteFriend(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, uid);
操作者收到OnFriendInfoChanged
String uid = ""; // 用户id
String remark = ""; // 备注名
OpenIMClient.getInstance().friendshipManager.setFriendRemark(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, uid, remark);
返回的数据里包含已拉入黑名单的好友,可以根据isBlacklist字段筛选。
OpenIMClient.getInstance().friendshipManager.getFriendList(new OnBase<List<UserInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<UserInfo> data) {
}
});
OpenIMClient.getInstance().friendshipManager.getRecvFriendApplicationList(new OnBase<List<FriendApplicationInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<FriendApplicationInfo> data) {
}
});
OpenIMClient.getInstance().friendshipManager.getSendFriendApplicationList(new OnBase<List<FriendApplicationInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<FriendApplicationInfo> data) {
}
});
操作者收到OnBlackAdded
String uid = ""; // 用户id
OpenIMClient.getInstance().friendshipManager.addBlacklist(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, uid);
OpenIMClient.getInstance().friendshipManager.getBlacklist(new OnBase<List<UserInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<UserInfo> data) {
}
});
操作者收到OnBlackDeleted
String uid = ""; // 用户id
OpenIMClient.getInstance().friendshipManager.removeBlacklist(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, uid);
操作者收到OnFriendApplicationAccepted、OnFriendAdded
申请者收到OnFriendApplicationAccepted、OnFriendAdded
String uid = ""; // 用户id
String handleMsg = ""; // 描述信息
OpenIMClient.getInstance().friendshipManager.acceptFriendApplication(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, uid, handleMsg);
操作者收到OnFriendApplicationRejected
申请者收到OnFriendApplicationRejected
String uid = ""; // 用户id
String handleMsg = ""; // 描述信息
OpenIMClient.getInstance().friendshipManager.refuseFriendApplication(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, uid, handleMsg);
直接进组无需同意。
被邀请者收到OnJoinedGroupAdded
群成员(不包括被邀请者)收到OnGroupMemberAdded
String groupID = ""; // 组ID
List<String> uidList = new ArrayList<>(); // 成员 userID 列表
String reason = ""; // 备注信息
OpenIMClient.getInstance().groupManager.inviteUserToGroup(new OnBase<List<GroupInviteResult>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<GroupInviteResult> data) {
}
}, groupID, uidList, reason);
被踢者收到OnJoinedGroupDeleted
群成员收到OnGroupMemberDeleted
String groupID = ""; // 组ID
List<String> uidList = new ArrayList<>(); // 成员 userID 列表
String reason = ""; // 备注信息
OpenIMClient.getInstance().groupManager.kickGroupMember(new OnBase<List<GroupInviteResult>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<GroupInviteResult> data) {
}
}, groupID, uidList, reason);
String groupID = ""; // 组ID
List<String> uidList = new ArrayList<>(); // 成员 userID 列表
OpenIMClient.getInstance().groupManager.getGroupMembersInfo(new OnBase<List<GroupMembersInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<GroupMembersInfo> data) {
}
}, groupID, uidList);
String groupID = ""; // 组ID
int filter = 0; // 1普通成员, 2群主,3管理员
int offset = 0; // 偏移量,每次开始的index值
int count = 0; // 每次拉取的数量
OpenIMClient.getInstance().groupManager.getGroupMemberList(new OnBase<List<GroupMembersInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<GroupMembersInfo> data) {
}
}, groupID, filter, offset, count);
OpenIMClient.getInstance().groupManager.getJoinedGroupList(new OnBase<List<GroupInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<GroupInfo> data) {
}
});
初始成员收到OnJoinedGroupAdded
String groupName = ""; // 组名
String faceURL = ""; // 头像
String notification = ""; // 群公告
String introduction = ""; // 群简介
int groupType = 0; // 类型
String ex = ""; // 扩展信息
List<GroupMemberRole> list = new ArrayList<>(); // 成员角色集合
OpenIMClient.getInstance().groupManager.createGroup(new OnBase<GroupInfo>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(GroupInfo data) {
}
}, groupName, faceURL, notification, introduction, groupType, ex, list);
群成员收到OnGroupInfoChanged
String groupID = ""; // 组ID
String groupName = ""; // 组名
String faceURL = ""; // 头像
String notification = ""; // 群公告
String introduction = ""; // 群简介
String ex = ""; // 扩展信息
OpenIMClient.getInstance().groupManager.setGroupInfo(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID, groupName, faceURL, notification, introduction, ex);
List<String> gidList = new ArrayList<>();
OpenIMClient.getInstance().groupManager.getGroupsInfo(new OnBase<List<GroupInfo>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<GroupInfo> data) {
}
}, gidList);
需要通过管理员同意。
申请者收到OnGroupApplicationAdded
群主+管理员收到OnGroupApplicationAdded
String groupID = ""; // 组ID
String reason = ""; // 备注信息
OpenIMClient.getInstance().groupManager.joinGroup(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID, reason);
退出者收到OnJoinedGroupDeleted
群成员收到OnGroupMemberDeleted
String groupID = ""; // 组ID
OpenIMClient.getInstance().groupManager.quitGroup(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID);
String groupID = ""; // 组ID
String newOwnerUserID = ""; // 新群主ID
OpenIMClient.getInstance().groupManager.transferGroupOwner(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID, newOwnerUserID);
作为群主或者管理员,获取收到的群成员申请进群列表。
OpenIMClient.getInstance().groupManager.getRecvGroupApplicationList(new OnBase<GroupApplicationInfo>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(GroupApplicationInfo data) {
}
});
OpenIMClient.getInstance().groupManager.getSendGroupApplicationList(new OnBase<GroupApplicationInfo>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(GroupApplicationInfo data) {
}
});
申请者收到OnJoinedGroupAdded OnGroupApplicationAccepted
群成员(不包括申请者)收到OnGroupMemberAdded
审批者(群主或者管理员)收到OnGroupMemberAdded OnGroupApplicationAccepted
String groupID = ""; // 组ID
String uid = ""; // 申请人userID
String handleMsg = ""; //备注信息
OpenIMClient.getInstance().groupManager.acceptGroupApplication(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID, uid, handleMsg);
申请者收到OnGroupApplicationRejected
审批者(群主或者管理员)收到OnGroupApplicationRejected
String groupID = ""; // 组ID
String uid = ""; // 申请人userID
String handleMsg = ""; //备注信息
OpenIMClient.getInstance().groupManager.refuseGroupApplication(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID, uid, handleMsg);
String groupID = ""; // 组ID
OpenIMClient.getInstance().groupManager.dismissGroup(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID);
String groupID = ""; // 组ID
boolean mute = true; // 开启禁言
OpenIMClient.getInstance().groupManager.changeGroupMute(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID, mute);
String groupID = ""; // 组ID
String userID = ""; // 群成员ID
long seconds = 0; // 禁言时长s
OpenIMClient.getInstance().groupManager.changeGroupMemberMute(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID, userID, mute);
String groupID = ""; // 组ID
String userID = ""; // 群成员ID
String groupNickname = ""; // 群成员昵称
OpenIMClient.getInstance().groupManager.setGroupMemberNickname(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID, userID, groupNickname);
List<String> keywordList; // 关键词
boolean isSearchGroupID; // 以群id为主
boolean isSearchGroupName ; // 以群名为主
OpenIMClient.getInstance().groupManager.setGroupMemberNickname(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, keywordList, isSearchGroupID, isSearchGroupName);
Message message = null; // 消息体;不为null,来自创建消息体方法的返回值
String userID = ""; // 接受消息的userID
String groupID = ""; // 接受消息的群ID
OfflinePushInfo offlinePushInfo = new OfflinePushInfo(); // 离线推送的消息备注;不为null
OpenIMClient.getInstance().messageManager.sendMessage(new OnMsgSendCallback() {
@Override
public void onError(int code, String error) {
}
@Override
public void onProgress(long progress) {
// 返回新的消息体,替换发送传入的,不然扯回消息会有bug
}
@Override
public void onSuccess(Message message) {
// 返回新的消息体;替换发送传入的,不然扯回消息会有bug
}
}, message, userID, groupID, offlinePushInfo);
Message startMsg = null; // 消息体,取界面上显示的消息体对象
String userID = ""; // 接受消息的userID
String groupID = ""; // 接受消息的群ID
int count = 20; // // 每次拉取的数量
OpenIMClient.getInstance().messageManager.getHistoryMessageList(new OnBase<List<Message>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<Message> data) {
}
}, userID, groupID, startMsg, count);
注:消息列表list,index == list.length -1 是最新的一条消息。 index == 0 是从最新的这条记录后的第19条。所以startMsg首次传null,
下次就是index == 0,以此类推。
撤回成功需要当前用户从列表里移除Message然后更新ui,而另外一方通过撤回监听(onRecvMessageRevoked)移除。
Message message = null; // 消息体,不为null,取界面上显示的消息体对象
OpenIMClient.getInstance().messageManager.revokeMessage(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, message);
Message message = null; // 消息体,不为null,取界面上显示的消息体对象
OpenIMClient.getInstance().messageManager.deleteMessageFromLocalStorage(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, message);
String receiverID = "";// 接收者 userID
String senderID = ""; // 发送中 userID
Message message = null; // 不为null,来自创建消息体方法的返回值
OpenIMClient.getInstance().messageManager.insertSingleMessageToLocalStorage(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, message, receiverID, senderID);
当调用此方法后,已读的消息会通过已读回执(onRecvC2CReadReceipt)告诉对方。
String userID = ""; // 接收者 userID
List<String> messageIDList = new ArrayList<>(); // 已读的消息id列表
OpenIMClient.getInstance().messageManager.markC2CMessageAsRead(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, userID, messageIDList);
String groupID = ""; // 组id
List<String> messageIDList = new ArrayList<>(); // 已读的消息id列表
OpenIMClient.getInstance().messageManager.markGroupMessageAsRead(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID, messageIDList);
会通过onRecvNewMessage回调
String userID = ""; // 接收者 userID
String msgTip = ""; // 自定义提示内容
OpenIMClient.getInstance().messageManager.typingStatusUpdate(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, userID, msgTip);
String userID = ""; // 接收者 userID
OpenIMClient.getInstance().messageManager.clearC2CHistoryMessage(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, userID);
String groupID = ""; // 组ID
OpenIMClient.getInstance().messageManager.clearGroupHistoryMessage(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID);
String text = ""; // 发送的内容
Message message = OpenIMClient.getInstance().messageManager.createTextMessage(text);
String text = ""; // 发送的内容
List<String> atUserIDList = new ArrayList<>(); // 被@的用户id列表
List<AtUserInfo> atUserInfoList; // id跟昵称映射关系
Message quoteMessage; // 引用消息
Message message = OpenIMClient.getInstance().messageManager.createTextAtMessage(text, atUserIDList, atUserInfoList, quoteMessage);
String imagePath = ""; // 图片路径
Message message = OpenIMClient.getInstance().messageManager.createImageMessage(imagePath);
注:initSDK时传入了数据缓存(dataDir)路径,如路径:A,这时需要你将图片复制到A路径下后,如 A/pic/a.png路径,imagePath的值:“/pic/a.png”。同以下其他消息的相对路径。
String imagePath = ""; // 图片路径
Message message = OpenIMClient.getInstance().messageManager.createImageMessageFromFullPath(imagePath);
String soundPath = ""; // 路径
long duration = 0; // 时长s
Message message = OpenIMClient.getInstance().messageManager.createSoundMessage(soundPath, duration);
String soundPath = ""; // 路径
long duration = 0; // 时长s
Message message = OpenIMClient.getInstance().messageManager.createSoundMessage(soundPath, duration);
String videoPath = ""; // 路径
String videoType = ""; // minetype
String snapshotPath = ""; // 站位缩略图
long duration = 0; // 时长s
Message message = OpenIMClient.getInstance().messageManager.createVideoMessage(videoPath, videoType, duration, snapshotPath);
String videoPath = ""; // 路径
String videoType = ""; // minetype
String snapshotPath = ""; // 站位缩略图
long duration = 0; // 时长s
Message message = OpenIMClient.getInstance().messageManager.createVideoMessage(videoPath, videoType, duration, snapshotPath);
String fileName = ""; // 文件名
String filePath = ""; // 路径
Message message = OpenIMClient.getInstance().messageManager.createFileMessage(filePath, fileName);
String fileName = ""; // 文件名
String filePath = ""; // 路径
Message message = OpenIMClient.getInstance().messageManager.createFileMessageFromFullPath(filePath, fileName);
Message message = null; // 消息体,不为null,取界面上显示的消息体对象
Message message1 = OpenIMClient.getInstance().messageManager.createForwardMessage(message);
List<Message> messageList = new ArrayList<>(); // 消息列表
String title = ""; // 标题
List<String> summaryList = new ArrayList<>(); // 每条消息的摘要
Message message = OpenIMClient.getInstance().messageManager.createMergerMessage(messageList, title, summaryList);
long latitude = 0;// 纬度
long longitude = 0; // 经度
String description = ""; // 位置描述信息
Message message = OpenIMClient.getInstance().messageManager.createLocationMessage(latitude, longitude, description);
String data = "";// 自定义内容
String extension = ""; // 扩展信息
String description = "";// 描述消息
Message message = OpenIMClient.getInstance().messageManager.createCustomMessage(data, extension, description);
String text = ""; // 回复内容
Message quoteMsg = null;// 不为null;被回复的消息体
Message message = OpenIMClient.getInstance().messageManager.createQuoteMessage(text,quoteMsg);
String content = ""; // 自定义内容
Message message = OpenIMClient.getInstance().messageManager.createCardMessage(content);
long index; // 自定义下标图片
String data; // 自定义内容图片
Message message = OpenIMClient.getInstance().messageManager.createFaceMessage(index, data);
String conversationID; //根据会话查询,如果是全局搜索传null
List<String> keywordList; //搜索关键词列表,目前仅支持一个关键词搜索
int keywordListMatchType; // 关键词匹配模式,1代表与,2代表或,暂时未用
List<String> senderUserIDList; // 指定消息发送的uid列表 暂时未用
List<Integer> messageTypeList; // 消息类型列表
int searchTimePosition; // 搜索的起始时间点。默认为0即代表从现在开始搜索。UTC 时间戳,单位:秒
int searchTimePeriod ; // 从起始时间点开始的过去时间范围,单位秒。默认为0即代表不限制时间范围,传24x60x60代表过去一天
int pageIndex ; // 当前页数
int count ; // 每页数量ll
OpenIMClient.getInstance().messageManager.searchLocalMessages(new OnBase<SearchResult>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(SearchResult data) {
}
}, conversationID, keywordList, keywordListMatchType, senderUserIDList, messageTypeList, searchTimePosition, searchTimePeriod, pageIndex, count);
Message message; // 被删除的消息
OpenIMClient.getInstance().messageManager.deleteMessageFromLocalAndSvr(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, message);
OpenIMClient.getInstance().messageManager.deleteAllMsgFromLocal(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
});
OpenIMClient.getInstance().messageManager.deleteAllMsgFromLocalAndSvr(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
});
String conversationID; // 会话ID
List<String> messageIDList; // 消息ID列表
OpenIMClient.getInstance().messageManager.markMessageAsReadByConID(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, conversationID, messageIDList);
String userID; // 单聊对象userID
OpenIMClient.getInstance().messageManager.clearC2CHistoryMessageFromLocalAndSvr(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, userID);
String groupID; // 群ID
OpenIMClient.getInstance().messageManager.clearGroupHistoryMessageFromLocalAndSvr(new OnBase<String>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(String data) {
}
}, groupID);
Message startMsg = null; // 消息体,取界面上显示的消息体对象
String userID = ""; // 接受消息的userID
String groupID = ""; // 接受消息的群ID
int count = 20; // // 每次拉取的数量
OpenIMClient.getInstance().messageManager.getHistoryMessageListReverse(new OnBase<List<Message>>() {
@Override
public void onError(int code, String error) {
}
@Override
public void onSuccess(List<Message> data) {
}
}, userID, groupID, startMsg, count);