可以参考另外两篇博客(另外感谢)
http://blog.csdn.net/chenshuaiforwork/article/details/52910974
http://blog.csdn.net/chenshuaiforwork/article/details/52710341
在https://www.qcloud.com/product/im中下载SDK、查看集成文档
ImSDK 支持 JDK 1.6 和 Android SDK version 14 以上系统。
导入jar、so,添加权限、注册IM广播服务
libs/bugly_1.3.0_imsdk_release.jar
libs/imsdk.jar
libs/mobilepb.jar
libs/qalsdk.jar
libs/tls_sdk.jar
libs/wup-1.0.0-SNAPSHOT.jar
libs/soload.jar
libs/armeabi/lib_imcore_jni_gyp.so
libs/armeabi/libBugly.so
libs/armeabi/libqalcodecwrapper.so
libs/armeabi/libqalmsfboot.so
libs/armeabi/libwtcrypto.so
libs/armeabi-v7a/lib_imcore_jni_gyp.so
libs/armeabi-v7a/libBugly.so
libs/armeabi-v7a/libqalcodecwrapper.so
libs/armeabi-v7a/libqalmsfboot.so
libs/armeabi-v7a/libwtcrypto.so
libs/arm64-v8a/lib_imcore_jni_gyp.so
libs/arm64-v8a/libBugly.so
libs/arm64-v8a/libqalcodecwrapper.so
libs/arm64-v8a/libqalmsfboot.so
libs/arm64-v8a/libwtcrypto.so
libs/x86/lib_imcore_jni_gyp.so
libs/x86/libBugly.so
libs/x86/libqalcodecwrapper.so
libs/x86/libqalmsfboot.so
libs/x86/libwtcrypto.so
libs/x86_64/lib_imcore_jni_gyp.so
libs/x86_64/libBugly.so
libs/x86_64/libqalcodecwrapper.so
libs/x86_64/libqalmsfboot.so
libs/x86_64/libwtcrypto.so
bugly_1.3.0_imsdk_release.jar crash上报jar包, 如不需要可删除,并调用TIMManager中的disableCrashReport进行禁用
imsdk.jar IMSDK的jar包
mobilepb.jar protobuffer处理相关jar包
qalsdk.jar SDK网络层jar包
tls_sdk.jar 帐号系统jar包
wup-1.0.0-SNAPSHOT.jar 无线统一协议jar包
soload.jar 提高imsdk so库的加载成功率
在Application
//设置用户状态变更监听器,在回调中进行相应的处理
TIMManager.getInstance().setUserStatusListener(new TIMUserStatusListener() {
@Override
public void onForceOffline() {
ToastUtil.showToast(CONTEXT, "账号在其他设备登陆");
}
@Override
public void onUserSigExpired() {
//票据过期,需要换票后重新登录
ToastUtil.showToast(CONTEXT, "请重新登陆");
}
});
if (MsfSdkUtils.isMainProcess(CONTEXT)) {
TIMManager.getInstance().setOfflinePushListener(new TIMOfflinePushListener() {
@Override
public void handleNotification(TIMOfflinePushNotification notification) {
if (notification.getGroupReceiveMsgOpt() == TIMGroupReceiveMessageOpt.ReceiveAndNotify) {
//消息被设置为需要提醒,暂时没有做点击后的处理
notification.doNotify(getApplicationContext(), R.mipmap.ic_launcher);
}
}
});
}
TIMManager.getInstance();
TIMManager.getInstance().init(this);
通过后台接口获取userSig(这是独立模式,托管模式看文档吧)
登陆SDK
/**
* 登陆IMSDK
*/
public static void loginSig(final Context context, String userSig, final String userName) {
TIMUser user = new TIMUser();
user.setIdentifier(userName);//userName用户名(id)
user.setAccountType(API.AccountType);//账号类型、由腾讯分配
user.setAppIdAt3rd(API.sdkAppId + "");//与AppId相同的字符串
//发起登录请求
TIMManager.getInstance().login(
API.sdkAppId, //sdkAppId,由腾讯分配
user,
userSig,//用户帐号签名,由私钥加密获得,具体请参考文档
new TIMCallBack() {//回调接口
@Override
public void onSuccess() {//登录成功
ToastUtil.showToast(context, "userSig登陆成功,用戶名:" + TIMManager.getInstance().getLoginUser());
}
@Override
public void onError(int code, String desc) {//登录失败
CodeToa(context, code);
}
});
}
创建房间
ArrayList list = new ArrayList<>();
list.add("");//被邀请人用户名
TIMGroupManager.getInstance().createGroup(
"Private", //群组类型: 目前仅支持私有群
list, //待加入群组的用户列表
RoomName, //群组名称
cb);
//创建房间回调
TIMValueCallBack cb = new TIMValueCallBack() {
@Override
public void onError(int code, String desc) {
AbLogUtil.e("创建", "create group failed: " + code + " desc");
ILVBSDK.CodeToa(getActivity(), code);
}
@Override
public void onSuccess(String s) { //回调返回创建的群组Id
Bundle bundle = new Bundle();
bundle.putString("RoomId", s);
MyApplication.openActivity(getActivity(), InterviewRoomActivity.class, bundle);
SharedPreferencesUtil.putSharePre(getActivity(), "RoomId", s);
AbLogUtil.e("房间Id", s);
ToastUtil.showToast(getActivity(), "创建成功,房间id:" + s);
}
};
有时间补充>