融云集成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

相关文章

Python中将嵌套列表扁平化的多种实现方法

《Python中将嵌套列表扁平化的多种实现方法》在Python编程中,我们常常会遇到需要将嵌套列表(即列表中包含列表)转换为一个一维的扁平列表的需求,本文将给大家介绍了多种实现这一目标的方法,需要的朋... 目录python中将嵌套列表扁平化的方法技术背景实现步骤1. 使用嵌套列表推导式2. 使用itert

在Spring Boot中集成RabbitMQ的实战记录

《在SpringBoot中集成RabbitMQ的实战记录》本文介绍SpringBoot集成RabbitMQ的步骤,涵盖配置连接、消息发送与接收,并对比两种定义Exchange与队列的方式:手动声明(... 目录前言准备工作1. 安装 RabbitMQ2. 消息发送者(Producer)配置1. 创建 Spr

如何在Spring Boot项目中集成MQTT协议

《如何在SpringBoot项目中集成MQTT协议》本文介绍在SpringBoot中集成MQTT的步骤,包括安装Broker、添加EclipsePaho依赖、配置连接参数、实现消息发布订阅、测试接口... 目录1. 准备工作2. 引入依赖3. 配置MQTT连接4. 创建MQTT配置类5. 实现消息发布与订阅

SpringBoot集成LiteFlow工作流引擎的完整指南

《SpringBoot集成LiteFlow工作流引擎的完整指南》LiteFlow作为一款国产轻量级规则引擎/流程引擎,以其零学习成本、高可扩展性和极致性能成为微服务架构下的理想选择,本文将详细讲解Sp... 目录一、LiteFlow核心优势二、SpringBoot集成实战三、高级特性应用1. 异步并行执行2

CSS3打造的现代交互式登录界面详细实现过程

《CSS3打造的现代交互式登录界面详细实现过程》本文介绍CSS3和jQuery在登录界面设计中的应用,涵盖动画、选择器、自定义字体及盒模型技术,提升界面美观与交互性,同时优化性能和可访问性,感兴趣的朋... 目录1. css3用户登录界面设计概述1.1 用户界面设计的重要性1.2 CSS3的新特性与优势1.

SpringBoot3应用中集成和使用Spring Retry的实践记录

《SpringBoot3应用中集成和使用SpringRetry的实践记录》SpringRetry为SpringBoot3提供重试机制,支持注解和编程式两种方式,可配置重试策略与监听器,适用于临时性故... 目录1. 简介2. 环境准备3. 使用方式3.1 注解方式 基础使用自定义重试策略失败恢复机制注意事项

SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程

《SpringBoot集成LiteFlow实现轻量级工作流引擎的详细过程》LiteFlow是一款专注于逻辑驱动流程编排的轻量级框架,它以组件化方式快速构建和执行业务流程,有效解耦复杂业务逻辑,下面给大... 目录一、基础概念1.1 组件(Component)1.2 规则(Rule)1.3 上下文(Conte

使用vscode搭建pywebview集成vue项目实践

《使用vscode搭建pywebview集成vue项目实践》:本文主要介绍使用vscode搭建pywebview集成vue项目实践,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录环境准备项目源码下载项目说明调试与生成可执行文件核心代码说明总结本节我们使用pythonpywebv

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

Maven项目中集成数据库文档生成工具的操作步骤

《Maven项目中集成数据库文档生成工具的操作步骤》在Maven项目中,可以通过集成数据库文档生成工具来自动生成数据库文档,本文为大家整理了使用screw-maven-plugin(推荐)的完... 目录1. 添加插件配置到 pom.XML2. 配置数据库信息3. 执行生成命令4. 高级配置选项5. 注意事