( 最近更新时间:2020-04-28 19:00:00 )
# 构建会话列表
IMkit 中提供了 ConversationListFragment 类. 构建后即可使用会话列表的功能.
# 效果展示
会话列表中用户信息需要单独设置. 用户信息具体如何设置请参考 设置用户信息

# 构建会话列表
创建会话 Activity (以
ConversationListActivity
为例) 以及 Activity 所对应的xml
布局 (以activity_conversation_list.xml
为例)activity_conversation_list.xml
布局中创建 View 容器用于动态添加 ConversationListFragment.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
已复制
2
3
4
5
6
7
8
9
10
- 在
ConversationListActivity
的onCreate
方法中创建并使用 ConversationListFragment.
class ConversationListActivity extends FragmentActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_conversation_list); ConversationListFragment conversationListFragment=new ConversationListFragment(); // 此处设置 Uri. 通过 appendQueryParameter 去设置所要支持的会话类型. 例如 // .appendQueryParameter(Conversation.ConversationType.PRIVATE.getName(),"false") // 表示支持单聊会话, false 表示不聚合显示, true 则为聚合显示 Uri uri = Uri.parse("rong://" + getActivity().getApplicationInfo().packageName).buildUpon() .appendPath("conversationlist") .appendQueryParameter(Conversation.ConversationType.PRIVATE.getName(), "false") //设置私聊会话是否聚合显示 .appendQueryParameter(Conversation.ConversationType.GROUP.getName(), "false")//群组 .appendQueryParameter(Conversation.ConversationType.PUBLIC_SERVICE.getName(), "false")//公共服务号 .appendQueryParameter(Conversation.ConversationType.APP_PUBLIC_SERVICE.getName(), "false")//订阅号 .appendQueryParameter(Conversation.ConversationType.SYSTEM.getName(), "true")//系统 .build(); conversationListFragment.setUri(uri); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.container, conversationListFragment); transaction.commit(); } }
已复制
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
AndroidManifest.xml
配置 Activity
SDK 内部通过隐式调用的方式来实现跳转到会话列表界面。需在 AndroidManifest.xml
中配置会话列表 ConversationListActivity
下面配置 intent-filter
.
- 必须要给 Activity 配置
intent-filter
. 否则使用 IMkit 中启动会话列表的方法将无效. android:host
的值需填写 App 的 ApplicationId.
<activity android:name="xxx.xxx.ConversationListActivity" 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="/conversationlist" android:scheme="rong" /> </intent-filter> </activity>
已复制
2
3
4
5
6
7
8
9
10
11
12
13
14
# 启动会话列表
SDK 内部通过隐式调用的方式来跳转到会话列表界面.
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
context | Context | 是 | 应用上下文 |
supportedConversation | Map<String, Boolean> | 是 | 设置要支持的会话类型. 1. String 为要支持的会话类型的值, 可通过 ConversationType (opens new window)的 getValue() 方法获取; 2. Boolean 为当前会话类型是否要支持聚合显示, true 为支持, false 为不支持 |
代码示例
Map<String, Boolean> supportedConversation = new HashMap<>(); supportedConversation.put(ConversationType.PRIVATE.getName(), false); RongIM.getInstance().startConversationList(Context , supportedConversation);
已复制
2
3
# 聚合会话列表
IMkit 中提供了 SubConversationListFragment 类. 构建后即可使用会话列表的功能.
# 效果展示
聚合会话列表中用户信息需要单独设置. 用户信息具体如何设置请参考 设置用户信息

# 构建聚合会话列表
创建会话 Activity (以
SubConversationListActivity
为例) 以及 Activity 所对应的xml
布局 (以activity_subconversation_list.xml
为例)activity_subconversation_list.xml
布局中创建 View 容器用于动态添加 SubConversationListFragment.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <FrameLayout android:id="@+id/container" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
已复制
2
3
4
5
6
7
8
9
10
- 在
SubConversationListActivity
的onCreate
方法中创建并使用 SubConversationListFragment.
SubConversationListFragment subconversationListFragment=new SubConversationListFragment(); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction(); transaction.replace(R.id.container, subconversationListFragment); transaction.commit();
已复制
2
3
4
5
AndroidManifest.xml
配置 Activity
SDK 内部通过隐式调用的方式来实现跳转到会话列表界面。需在 AndroidManifest.xml
中配置会话列表 SubConversationListActivity
下面配置 intent-filter
.
- 必须要给 Activity 配置
intent-filter
. 否则使用 IMkit 中启动会话列表的方法将无效. android:host
的值需填写 App 的 ApplicationId.
<activity android:name="xxx.xxx.SubConversationListActivity" 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="/subconversationlist" android:scheme="rong" /> </intent-filter> </activity>
已复制
2
3
4
5
6
7
8
9
10
11
12
13
14
# 启动聚合会话列表
SDK 内部通过隐式调用的方式来跳转到会话列表界面.
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
context | Context | 是 | 应用上下文 |
conversationType | ConversationType (opens new window) | 是 | 会话类型. 当前为 ConversationType.PRIVATE |
代码示例
RongIM.getInstance().startSubConversationList(Context , ConversationType.PRIVATE);
已复制