參考資料:http://www.rongcloud.cn/docs/android.html#配置會話列表
一.靜態註冊
1.在需要顯示會話列表的Activity佈局文件中,直接引用:
注意 android:name 固定爲融雲的 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">
<fragment
android:id="@+id/conversationlist"
android:name="io.rong.imkit.fragment.ConversationListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
2.配置 intent-filter:
融雲 SDK 是通過隱式調用的方式來實現界面跳轉的。因此您需要在 AndroidManifest.xml 中,您的會話列表 Activity 下面配置 intent-filter,其中,android:host 是您應用的包名,需要手動修改,其他請保持不變。
<!--會話列表-->
<activity
android:name="io.rong.fast.activity.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="io.rong.fast"
android:pathPrefix="/conversationlist"
android:scheme="rong" />
</intent-filter>
</activity>
3.啓動方式:
HashMap<String, Boolean> hashMap = new HashMap<>();
//會話類型 以及是否聚合顯示
hashMap.put(Conversation.ConversationType.PRIVATE.getName(),false);
hashMap.put(Conversation.ConversationType.PUSH_SERVICE.getName(),true);
hashMap.put(Conversation.ConversationType.SYSTEM.getName(),true);
RongIM.getInstance().startConversationList(this,hashMap);
二、動態註冊:
佈局文件:
<!--會話列表-->
<FrameLayout
android:id="@+id/rong_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/line1"
/>
//會話列表
ConversationListFragment conversationListFragment = new ConversationListFragment();
Uri uri = Uri.parse("rong://" + getActivity().getApplicationInfo().packageName).buildUpon()
.appendPath("conversationlist") .appendQueryParameter(Conversation.ConversationType.PRIVATE.getName(), "false") //設置私聊會話,該會話聚合顯示
.appendQueryParameter(Conversation.ConversationType.SYSTEM.getName(), "true")//設置系統會話,該會話非聚合顯示
.build();
conversationListFragment.setUri(uri);
FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.add(R.id.rong_container,conversationListFragment);
transaction.commit();
三、會話界面配置
1. 會話 Fragment 跟會話列表是完全一致的,您可以用同樣的方式快速的配置好。
配置佈局文件
這是您的會話 Activity 對應的佈局文件 conversation.xml,注意 android:name 固定爲融雲的 ConversationFragment。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/conversation"
android:name="io.rong.imkit.fragment.ConversationFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
2.配置 intent-filter
在 AndroidManifest.xml 中,會話 Activity 下面配置 intent-filter。 注意請修改 android:host 爲您應用的包名,其他保持不變。
<!--會話界面-->
<activity
android:name="io.rong.fast.activity.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="io.rong.fast"
android:pathPrefix="/conversation/"
android:scheme="rong" />
</intent-filter>
</activity>
3.會話界面設置頂部顯示好友暱稱:
/**
* crate by longShun on 2017.2.18
* 每一個會話界面
*/
public class ConversationActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friend_messages);
//會話界面 對方id
//String targetId = getIntent().getData().getQueryParameter("targetId");
//對方 暱稱
String title = getIntent().getData().getQueryParameter("title");
if (!TextUtils.isEmpty(title)){
//todo 設置標題爲對方暱稱
}
}
}
4.啓動方式
1. 自動啓動:當我們點擊會話列表中某個會話時,融雲會觸發自己實現的點擊事件,隱式啓動會話界面,從而進入某一個會話界面,所以我們可以不用去處理會話列表item的點擊事件;
2.參考下面手動啓動的方式
四、聚合會話列表
1.配置佈局文件
這是您的聚合會話列表 Activity 對應的佈局文件:subconversationlist.xml。 注意 android:name 固定爲融雲的 SubConversationListFragment。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/subconversationlist"
android:name="io.rong.imkit.fragment.SubConversationListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
2.配置 intent-filter
在 AndroidManifest.xml 中, 聚合會話 Activity 下面配置 intent-filter。 注意請修改 android:host 爲您應用的包名,其他保持不變。
<!--聚合會話列表-->
<activity
android:name="io.rong.fast.activity.SubConversationListActivtiy"
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="io.rong.fast"
android:pathPrefix="/subconversationlist"
android:scheme="rong" />
</intent-filter>
</activity>
五、手動啓動各種界面
/**
* <p>啓動會話界面。</p>
* <p>使用時,可以傳入多種會話類型 {@link io.rong.imlib.model.Conversation.ConversationType} 對應不同的會話類型,開啓不同的會話界面。
* 如果傳入的是 {@link io.rong.imlib.model.Conversation.ConversationType#CHATROOM},sdk 會默認調用
* {@link RongIMClient#joinChatRoom(String, int, RongIMClient.OperationCallback)} 加入聊天室。
* 如果你的邏輯是,只允許加入已存在的聊天室,請使用接口 {@link #startChatRoomChat(Context, String, boolean)} 並且第三個參數爲 true</p>
*
* @param context 應用上下文。
* @param conversationType 會話類型。
* @param targetId 根據不同的 conversationType,可能是用戶 Id、討論組 Id、羣組 Id 或聊天室 Id。
* @param title 聊天的標題,開發者可以在聊天界面通過 intent.getData().getQueryParameter("title") 獲取該值, 再手動設置爲標題。
*/
public void startConversation(Context context, Conversation.ConversationType conversationType, String targetId, String title)
/**
* 啓動會話列表界面。
*
* @param context 應用上下文。
* @param supportedConversation 定義會話列表支持顯示的會話類型,及對應的會話類型是否聚合顯示。
* 例如:supportedConversation.put(Conversation.ConversationType.PRIVATE.getName(), false) 非聚合式顯示 private 類型的會話。
*/
public void startConversationList(Context context, Map<String, Boolean> supportedConversation)
/**
* 啓動聚合後的某類型的會話列表。<br> 例如:如果設置了單聊會話爲聚合,則通過該方法可以打開包含所有的單聊會話的列表。
*
* @param context 應用上下文。
* @param conversationType 會話類型。
*/
public void startSubConversationList(Context context, Conversation.ConversationType conversationType)