Android studio接入融云IM

说明:
官方网址:http://www.rongcloud.cn/

1.融云SDK 将各部分功能以插件化的形式独立提供,开发者可以根据自己的需要,自由组合下载。
2.IM 界面组件 - IMKit ,IM 通讯能力库 - IMLib ,注意使用IMKit的时候必须要引入IMLib,但可以单独使用IMLib,由自己完全开发的界面代替IMKit.
3.PushLib用于融云推送的保活,若想在退出APP时不接受IM的推送(有未读消息时手机振动或者响铃)可不引入。

接入注意事项:
1.配置会话界面的时候,需要在自己的xml中布局中引入融云固定的fragment,需要自己需要的界面对应融云具体的那个fragment。官方文档写的不全面,不确定的地方要以提工单的方式去问支撑人员。下面以接入群聊界面为例说明:
a.布局文件activity_conversation的代码:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<!-- 注意fragment的正确性-->
    <fragment
        android:id="@+id/conversation"
        android:name="io.rong.imkit.fragment.ConversationFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
</FrameLayout>

b.清单文件中的配置:

<!-- 融云群聊 -->
        <activity
            android:name=".ui.home.chat.ConversationActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden|adjustResize">
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <data
                <!-- 注意此处为自己的包名-->
                    android:host="${applicationId}"
                    android:pathPrefix="/conversation/"
                    android:scheme="rong"/>
            </intent-filter>
        </activity>

c.进入聊天界面:

//groupID:群聊id  groupName:群聊名称
RongIM.getInstance().startGroupChat(getActivity(), groupID, groupName);

注意:此处并没有直接跳转到自己新建的ConversationActivity,因为此方法默认会调用融云群聊的io.rong.imkit.fragment.ConversationFragment,只不过此fragment依附于ConversationActivity,增加UI样的自定义性。
d.真正实现群聊-实现群组成员()

RongIM.getInstance().setGroupMembersProvider(new RongIM.IGroupMembersProvider() {
            @Override
            public void getGroupMembers(String groupId, RongIM.IGroupMemberCallback callback) {
                // TODO 获取群组成员信息列表,此处模拟数据
                List<UserInfo> userInfoList = new ArrayList<UserInfo>();
                userInfoList.add(new UserInfo("001", "dyb", null));
                userInfoList.add(new UserInfo("002", "lf", null));
                userInfoList.add(new UserInfo("003", "张宇", null));
                userInfoList.add(new UserInfo("004", "胡丹丹", null));
                callback.onGetGroupMembersResult(userInfoList);

            }
        });

2.获取群聊未读消息方法
官方支撑客服不一定靠谱,建议下载官方demo APP,在demo中全局搜不到方法不要采用。
当前activity implements IUnReadMessageObserver,重写onCountChanged(int count),返回的count即为未读消息数量。

猜你喜欢

转载自blog.csdn.net/u010296640/article/details/76728444