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

相关文章

Spring Boot集成SLF4j从基础到高级实践(最新推荐)

《SpringBoot集成SLF4j从基础到高级实践(最新推荐)》SLF4j(SimpleLoggingFacadeforJava)是一个日志门面(Facade),不是具体的日志实现,这篇文章主要介... 目录一、日志框架概述与SLF4j简介1.1 为什么需要日志框架1.2 主流日志框架对比1.3 SLF4

Spring Boot集成Logback终极指南之从基础到高级配置实战指南

《SpringBoot集成Logback终极指南之从基础到高级配置实战指南》Logback是一个可靠、通用且快速的Java日志框架,作为Log4j的继承者,由Log4j创始人设计,:本文主要介绍... 目录一、Logback简介与Spring Boot集成基础1.1 Logback是什么?1.2 Sprin

C++类和对象之初始化列表的使用方式

《C++类和对象之初始化列表的使用方式》:本文主要介绍C++类和对象之初始化列表的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C++初始化列表详解:性能优化与正确实践什么是初始化列表?初始化列表的三大核心作用1. 性能优化:避免不必要的赋值操作2. 强

springboot集成Lucene的详细指南

《springboot集成Lucene的详细指南》这篇文章主要为大家详细介绍了springboot集成Lucene的详细指南,文中的示例代码讲解详细,具有一定的借鉴价值,感兴趣的小伙伴可以跟随小编一起... 目录添加依赖创建配置类创建实体类创建索引服务类创建搜索服务类创建控制器类使用示例以下是 Spring

Spring Boot 集成 Quartz并使用Cron 表达式实现定时任务

《SpringBoot集成Quartz并使用Cron表达式实现定时任务》本篇文章介绍了如何在SpringBoot中集成Quartz进行定时任务调度,并通过Cron表达式控制任务... 目录前言1. 添加 Quartz 依赖2. 创建 Quartz 任务3. 配置 Quartz 任务调度4. 启动 Sprin

Python列表去重的4种核心方法与实战指南详解

《Python列表去重的4种核心方法与实战指南详解》在Python开发中,处理列表数据时经常需要去除重复元素,本文将详细介绍4种最实用的列表去重方法,有需要的小伙伴可以根据自己的需要进行选择... 目录方法1:集合(set)去重法(最快速)方法2:顺序遍历法(保持顺序)方法3:副本删除法(原地修改)方法4:

SpringBoot集成Milvus实现数据增删改查功能

《SpringBoot集成Milvus实现数据增删改查功能》milvus支持的语言比较多,支持python,Java,Go,node等开发语言,本文主要介绍如何使用Java语言,采用springboo... 目录1、Milvus基本概念2、添加maven依赖3、配置yml文件4、创建MilvusClient

springboot简单集成Security配置的教程

《springboot简单集成Security配置的教程》:本文主要介绍springboot简单集成Security配置的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录集成Security安全框架引入依赖编写配置类WebSecurityConfig(自定义资源权限规则

springboot集成Deepseek4j的项目实践

《springboot集成Deepseek4j的项目实践》本文主要介绍了springboot集成Deepseek4j的项目实践,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录Deepseek4j快速开始Maven 依js赖基础配置基础使用示例1. 流式返回示例2. 进阶

Spring Boot 集成 Quartz 使用Cron 表达式实现定时任务

《SpringBoot集成Quartz使用Cron表达式实现定时任务》本文介绍了如何在SpringBoot项目中集成Quartz并使用Cron表达式进行任务调度,通过添加Quartz依赖、创... 目录前言1. 添加 Quartz 依赖2. 创建 Quartz 任务3. 配置 Quartz 任务调度4. 启