融云集成4--会话列表,会话界面的集成

2024-05-13 01:32

本文主要是介绍融云集成4--会话列表,会话界面的集成,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

参考资料: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 {@Overrideprotected 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)

这篇关于融云集成4--会话列表,会话界面的集成的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/984306

相关文章

Debezium 与 Apache Kafka 的集成方式步骤详解

《Debezium与ApacheKafka的集成方式步骤详解》本文详细介绍了如何将Debezium与ApacheKafka集成,包括集成概述、步骤、注意事项等,通过KafkaConnect,D... 目录一、集成概述二、集成步骤1. 准备 Kafka 环境2. 配置 Kafka Connect3. 安装 D

Spring AI集成DeepSeek的详细步骤

《SpringAI集成DeepSeek的详细步骤》DeepSeek作为一款卓越的国产AI模型,越来越多的公司考虑在自己的应用中集成,对于Java应用来说,我们可以借助SpringAI集成DeepSe... 目录DeepSeek 介绍Spring AI 是什么?1、环境准备2、构建项目2.1、pom依赖2.2

Python如何计算两个不同类型列表的相似度

《Python如何计算两个不同类型列表的相似度》在编程中,经常需要比较两个列表的相似度,尤其是当这两个列表包含不同类型的元素时,下面小编就来讲讲如何使用Python计算两个不同类型列表的相似度吧... 目录摘要引言数字类型相似度欧几里得距离曼哈顿距离字符串类型相似度Levenshtein距离Jaccard相

Redis存储的列表分页和检索的实现方法

《Redis存储的列表分页和检索的实现方法》在Redis中,列表(List)是一种有序的数据结构,通常用于存储一系列元素,由于列表是有序的,可以通过索引来访问元素,因此可以很方便地实现分页和检索功能,... 目录一、Redis 列表的基本操作二、分页实现三、检索实现3.1 方法 1:客户端过滤3.2 方法

Java中Springboot集成Kafka实现消息发送和接收功能

《Java中Springboot集成Kafka实现消息发送和接收功能》Kafka是一个高吞吐量的分布式发布-订阅消息系统,主要用于处理大规模数据流,它由生产者、消费者、主题、分区和代理等组件构成,Ka... 目录一、Kafka 简介二、Kafka 功能三、POM依赖四、配置文件五、生产者六、消费者一、Kaf

Python实现将实体类列表数据导出到Excel文件

《Python实现将实体类列表数据导出到Excel文件》在数据处理和报告生成中,将实体类的列表数据导出到Excel文件是一项常见任务,Python提供了多种库来实现这一目标,下面就来跟随小编一起学习一... 目录一、环境准备二、定义实体类三、创建实体类列表四、将实体类列表转换为DataFrame五、导出Da

Python中的可视化设计与UI界面实现

《Python中的可视化设计与UI界面实现》本文介绍了如何使用Python创建用户界面(UI),包括使用Tkinter、PyQt、Kivy等库进行基本窗口、动态图表和动画效果的实现,通过示例代码,展示... 目录从像素到界面:python带你玩转UI设计示例:使用Tkinter创建一个简单的窗口绘图魔法:用

Python中构建终端应用界面利器Blessed模块的使用

《Python中构建终端应用界面利器Blessed模块的使用》Blessed库作为一个轻量级且功能强大的解决方案,开始在开发者中赢得口碑,今天,我们就一起来探索一下它是如何让终端UI开发变得轻松而高... 目录一、安装与配置:简单、快速、无障碍二、基本功能:从彩色文本到动态交互1. 显示基本内容2. 创建链

SpringCloud集成AlloyDB的示例代码

《SpringCloud集成AlloyDB的示例代码》AlloyDB是GoogleCloud提供的一种高度可扩展、强性能的关系型数据库服务,它兼容PostgreSQL,并提供了更快的查询性能... 目录1.AlloyDBjavascript是什么?AlloyDB 的工作原理2.搭建测试环境3.代码工程1.

SpringBoot使用注解集成Redis缓存的示例代码

《SpringBoot使用注解集成Redis缓存的示例代码》:本文主要介绍在SpringBoot中使用注解集成Redis缓存的步骤,包括添加依赖、创建相关配置类、需要缓存数据的类(Tes... 目录一、创建 Caching 配置类二、创建需要缓存数据的类三、测试方法Spring Boot 熟悉后,集成一个外