一.设置群聊与单聊消息免打扰功能:

1.下面直接进入逻辑代码:

实现监听事件:

 /*** 设置会话列表界面操作的监听器。*/RongIM.setConversationListBehaviorListener(new MyConversationListBehaviorListener());
public class MyConversationListBehaviorListener implements RongIM.ConversationListBehaviorListener {}

2.上面的监听有四个方法:

(1).头像点击事件

@Override
public boolean onConversationPortraitClick(Context context, Conversation.ConversationType conversationType, String s) {
                return false;
 }

(2).头像长按事件

@Override
 public boolean onConversationPortraitLongClick(Context context, Conversation.ConversationType conversationType, String s) {
    return false; 
 }

(3).消息点击事件

@Override
public boolean onConversationClick(Context context, View view, UIConversation uiConversation) {
       return false;
}

(4).消息长按事件

@Override
public boolean onConversationLongClick(final Context context, View view, final UIConversation uiConversation) {
       return false;
}

3.我们需要处理的就是onConversationLongClick()方法,首先把返回值更改为true,调用的时候就会调用我们自定义的弹框,而不是融云提供的

核心代码:

 public class MyConversationListBehaviorListener implements RongIM.ConversationListBehaviorListener {/*** 当点击会话头像后执行。** @param context          上下文。* @param conversationType 会话类型。* @param targetId         被点击的用户id。* @return 如果用户自己处理了点击后的逻辑处理,则返回 true,否则返回 false,false 走融云默认处理方式。*/@Overridepublic boolean onConversationPortraitClick(Context context, Conversation.ConversationType conversationType, String targetId) {
//            Toast.makeText(context,targetId,Toast.LENGTH_SHORT).show();return false;}/*** 当长按会话头像后执行。** @param context          上下文。* @param conversationType 会话类型。* @param targetId         被点击的用户id。* @return 如果用户自己处理了点击后的逻辑处理,则返回 true,否则返回 false,false 走融云默认处理方式。*/@Overridepublic boolean onConversationPortraitLongClick(Context context, Conversation.ConversationType conversationType, String targetId) {
//            Toast.makeText(context,"长按 "+targetId,Toast.LENGTH_SHORT).show();return false;}/*** 长按会话列表中的 item 时执行。** @param context        上下文。* @param view           触发点击的 View。* @param uiConversation 长按时的会话条目。* @return 如果用户自己处理了长按会话后的逻辑处理,则返回 true, 否则返回 false,false 走融云默认处理方式。*/@Overridepublic boolean onConversationLongClick(Context context, View view, UIConversation uiConversation) {Conversation.ConversationType conversationType = uiConversation.getConversationType();//判断聊天类型,3:群聊、1:单聊等int conversationTypeValue = conversationType.getValue();//下面无需判断聊天类型
//            String[] split = uiConversation.getConversationTargetId().split(Constant.TARGETID);
//            int conversationTarget = Integer.parseInt(split[1]);//先获取单聊和群聊免打扰的状态值if (conversationTypeValue == 3) {//群聊RongIM.getInstance().getConversationNotificationStatus(Conversation.ConversationType.GROUP,uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {@Overridepublic void onSuccess(final Conversation.ConversationNotificationStatus conversationNotificationStatus) {final int value = conversationNotificationStatus.getValue();final Conversation.ConversationNotificationStatus conversationNotificationStatus1;if (value == 1) {conversationNotificationStatus1 = conversationNotificationStatus.setValue(0);disturb = getString(R.string.donot_disturb2);} else {conversationNotificationStatus1 = conversationNotificationStatus.setValue(1);disturb = getString(R.string.cancel_no_bother);}}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});} else if (conversationTypeValue == 1) {RongIM.getInstance().getConversationNotificationStatus(Conversation.ConversationType.PRIVATE,uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {@Overridepublic void onSuccess(final Conversation.ConversationNotificationStatus conversationNotificationStatus) {final int value = conversationNotificationStatus.getValue();final Conversation.ConversationNotificationStatus conversationNotificationStatus1;if (value == 1) {disturb = getString(R.string.donot_disturb2);} else {disturb = getString(R.string.cancel_no_bother);}}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}//弹出的“保存图片”的DialogAlertDialog.Builder builder = new AlertDialog.Builder(getActivity());builder.setItems(new String[]{getString(R.string.pet_detail), disturb, getString(R.string.cancel)}, new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {switch (which) {case 0:RongIM.getInstance().removeConversation(uiConversation.getConversationType(), uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Boolean>() {@Overridepublic void onSuccess(Boolean aBoolean) {
//                            RongIMClient.getInstance().deleteMessages(new int[]{uiConversation.get});RongIM.getInstance().removeConversation(uiConversation.getConversationType(), uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Boolean>() {@Overridepublic void onSuccess(Boolean aBoolean) {RongIM.getInstance().getConversationList(new RongIMClient.ResultCallback<List<Conversation>>() {@Overridepublic void onSuccess(List<Conversation> conversationeees) {//清除对应的用户对话记录RongIM.getInstance().clearMessages(uiConversation.getConversationType(), uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Boolean>() {@Overridepublic void onSuccess(Boolean aBoolean) {}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});break;case 1:if (conversationTypeValue == 3) {//群聊RongIM.getInstance().getConversationNotificationStatus(Conversation.ConversationType.GROUP,uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {@Overridepublic void onSuccess(final Conversation.ConversationNotificationStatus conversationNotificationStatus) {final int value = conversationNotificationStatus.getValue();final Conversation.ConversationNotificationStatus conversationNotificationStatus1;if (value == 1) {conversationNotificationStatus1 = conversationNotificationStatus.setValue(0);
//                                                    disturb = getString(R.string.donot_disturb2);} else {conversationNotificationStatus1 = conversationNotificationStatus.setValue(1);
//                                                    disturb = getString(R.string.cancel_no_bother);}RongIM.getInstance().setConversationNotificationStatus(Conversation.ConversationType.GROUP,uiConversation.getConversationTargetId(), conversationNotificationStatus1, new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {@Overridepublic void onSuccess(Conversation.ConversationNotificationStatus conversationNotificationStatus) {}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});} else if (conversationTypeValue == 1) {RongIM.getInstance().getConversationNotificationStatus(Conversation.ConversationType.PRIVATE,uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {@Overridepublic void onSuccess(final Conversation.ConversationNotificationStatus conversationNotificationStatus) {final int value = conversationNotificationStatus.getValue();final Conversation.ConversationNotificationStatus conversationNotificationStatus1;if (value == 1) {conversationNotificationStatus1 = conversationNotificationStatus.setValue(0);} else {conversationNotificationStatus1 = conversationNotificationStatus.setValue(1);}RongIM.getInstance().setConversationNotificationStatus(Conversation.ConversationType.PRIVATE,uiConversation.getConversationTargetId(), conversationNotificationStatus1, new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {@Overridepublic void onSuccess(Conversation.ConversationNotificationStatus conversationNotificationStatus) {}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}break;case 2:break;}}});builder.show();//删除弹框提示
//            final AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
//            builder.setTitle(getResources().getString(R.string.delete_sure));builder.setMessage("删除吗?");
//            builder.setPositiveButton(getResources().getString(R.string.sure), new DialogInterface.OnClickListener() {
//                @Override
//                public void onClick(DialogInterface dialog, int which) {
//                    RongIM.getInstance().removeConversation(uiConversation.getConversationType(), uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Boolean>() {
//                        @Override
//                        public void onSuccess(Boolean aBoolean) {RongIMClient.getInstance().deleteMessages(new int[]{uiConversation.get});
//                            RongIM.getInstance().removeConversation(uiConversation.getConversationType(), uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Boolean>() {
//                                @Override
//                                public void onSuccess(Boolean aBoolean) {
//                                    RongIM.getInstance().getConversationList(new RongIMClient.ResultCallback<List<Conversation>>() {
//
//                                        @Override
//                                        public void onSuccess(List<Conversation> conversationeees) {
//
//                                            //清除对应的用户对话记录
//                                            RongIM.getInstance().clearMessages(uiConversation.getConversationType(), uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Boolean>() {
//                                                @Override
//                                                public void onSuccess(Boolean aBoolean) {
//
//                                                }
//
//                                                @Override
//                                                public void onError(RongIMClient.ErrorCode errorCode) {
//
//                                                }
//                                            });
//
//
//                                        }
//
//                                        @Override
//                                        public void onError(RongIMClient.ErrorCode errorCode) {
//
//                                        }
//                                    });
//
//                                }
//
//                                @Override
//                                public void onError(RongIMClient.ErrorCode errorCode) {
//
//                                }
//                            });
//
//                        }
//
//                        @Override
//                        public void onError(RongIMClient.ErrorCode errorCode) {
//
//                        }
//                    });
//                    dialog.dismiss();
//                }
//            });
//            builder.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
//                @Override
//                public void onClick(DialogInterface dialog, int which) {
//                    dialog.dismiss();
//                }
//            });
//            AlertDialog alertDialog = builder.create();
//            alertDialog.show();//            RongIM.getInstance().removeConversation(uiConversation.getConversationType(),uiConversation.getConversationTargetId());//删除会话列表中的消息
//            //删除会话列表
//            RongIM.getInstance().removeConversation(Conversation.ConversationType.PRIVATE, uiConversation.getConversationTargetId());//个人 在自己删除对方好友关系
//            RongIM.getInstance().getRongIMClient().removeConversation(Conversation.ConversationType.PRIVATE, split[1], new RongIMClient.ResultCallback<Boolean>() {
//                @Override
//                public void onSuccess(Boolean aBoolean) {
//                    Toast.makeText(context,aBoolean + "" ,Toast.LENGTH_SHORT).show();
//                    getData(conversationTarget);
//                }
//
//                @Override
//                public void onError(RongIMClient.ErrorCode errorCode) {
//
//                }
//            });return true;}/*** 点击会话列表中的 item 时执行。** @param context        上下文。* @param view           触发点击的 View。* @param uiConversation 会话条目。* @return 如果用户自己处理了点击会话后的逻辑处理,则返回 true, 否则返回 false,false 走融云默认处理方式。*/@Overridepublic boolean onConversationClick(Context context, View view, UIConversation uiConversation) {return false;}}

上述代码就是实现单聊与群聊消息免打扰的设置,注释的代码仅供参考。

4.设置单聊与群聊的免打扰状态:

 RongIM.getInstance().setConversationNotificationStatus(Conversation.ConversationType.GROUP,//群聊或单聊uiConversation.getConversationTargetId(),//群ID或单聊IDConversation.ConversationNotificationStatus.DO_NOT_DISTURB,//静音..打开改为NOTIFY即可new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() { //设置成功后的回调@Overridepublic void onSuccess(Conversation.ConversationNotificationStatus conversationNotificationStatus) {final int value = conversationNotificationStatus.getValue();final Conversation.ConversationNotificationStatus conversationNotificationStatus1;if(value==1){conversationNotificationStatus1=conversationNotificationStatus.setValue(0);disturb="免打扰";}else{conversationNotificationStatus1=conversationNotificationStatus.setValue(1);disturb="取消免打扰";}RongIM.getInstance().setConversationNotificationStatus(Conversation.ConversationType.GROUP,uiConversation.getConversationTargetId(), conversationNotificationStatus1, new RongIMClient.ResultCallback<Conversation.ConversationNotificationStatus>() {@Overridepublic void onSuccess(Conversation.ConversationNotificationStatus conversationNotificationStatus) {T.showShort("设置成功");}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {T.showShort("设置失败");}});}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});

二.单聊与群聊消息删除功能:

1.在对应的弹框中实现删除逻辑(上述核心代码中实现了两个简单的弹框,可以参考):

  RongIM.getInstance().removeConversation(uiConversation.getConversationType(), uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Boolean>() {@Overridepublic void onSuccess(Boolean aBoolean) {
//                            RongIMClient.getInstance().deleteMessages(new int[]{uiConversation.get});RongIM.getInstance().removeConversation(uiConversation.getConversationType(), uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Boolean>() {@Overridepublic void onSuccess(Boolean aBoolean) {RongIM.getInstance().getConversationList(new RongIMClient.ResultCallback<List<Conversation>>() {@Overridepublic void onSuccess(List<Conversation> conversationeees) {//清除对应的用户对话记录RongIM.getInstance().clearMessages(uiConversation.getConversationType(), uiConversation.getConversationTargetId(), new RongIMClient.ResultCallback<Boolean>() {@Overridepublic void onSuccess(Boolean aBoolean) {}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});}@Overridepublic void onError(RongIMClient.ErrorCode errorCode) {}});

Android 融云单聊与群聊消息免打扰功能设置与消息删除功能实现相关推荐

  1. 融云及时通讯 加入群聊

    //跳转到融云群聊天界面 RongIM.getInstance().startConversation(AddGroupChatActivity.this, Conversation.Conversa ...

  2. Android 项目接入网易云信IM单聊,群聊

    首先需要去网易云信注册账号: https://app.yunxin.163.com/index?clueFrom=nim&from=nim#/create 账号注册成功后去新建项目拿到集成需要 ...

  3. LayIM 3.9.1与ASP.NET SignalR实现Web聊天室快速入门(七)之LayIM与MVC数据交互实现单聊和群聊

    前言 本系列文章特点:使用ASP.NET SignalR和LayIM快速入门对接,实现一对一聊天,群聊,添加聊天群组,查找聊天记录等功能.源代码不包含LayIM的源代码,因为官方并没开源属于收费资源, ...

  4. Android 仿钉钉、微信 群聊组合头像

    CombineBitmap 项目地址:SheHuan/CombineBitmap 简介: Android 仿钉钉.微信 群聊组合头像 更多:作者   提 Bug 标签: 效果预览   功能 生成类似钉 ...

  5. Android 仿钉钉、微信 群聊组合头像,Android插件化入门指南

    简介: Android 仿钉钉.微信 群聊组合头像 更多:作者   提 Bug 标签: 效果预览 | | | |   | | - | - | - | - | | | | | | | | | | | 功 ...

  6. socketio单聊,群聊

    一个简单的聊天程序,功能有单聊,群聊 页面如下所示: Name后面跟的是当前登录人的名字,下方的列表是当前在线的用户,双击该用户名后,可以给该用户发送消息.再次双击同一用户,下方会显示给所有(All) ...

  7. 陌生交友发布动态圈子单聊打招呼群聊app开发

    陌生交友发布动态圈子单聊打招呼群聊app开发 功能有,发布圈子,发布动态,查看附近的人,发布活动,实人认证,个人主页,相册查看,单聊,群聊. 即时通讯第三方goeasy接口. 好的,以下是陌生交友应用 ...

  8. 融云android聊天界面,Android 融云IM集成以及使用详解(一)

    Android 融云IM集成以及使用详解(一) 集成 1.具体的集成步骤就不在详细介绍,我们只说干货,附上融云IM官方文档地址,里面有更为详细的集成介绍 https://www.rongcloud.c ...

  9. Android 融云IM集成以及使用详解(二)

    Android 融云IM集成以及使用详解(二) 上篇讲解了集成和好友列表和消息记录的使用,这篇将讲解聊天界面和群聊界面的使用 先附上一张效果图 先介绍布局文件 <LinearLayout xml ...

最新文章

  1. python简单单元测试示范卷_Python 单元测试的简单示例
  2. fatal error lnk1561: 必须定义入口点_链表中是否有环以及找环的入口问题总结
  3. CSE 5/7350 – Project
  4. 安装Ubuntu 20.04.1 LTS (Focal Fossa)到U盘并安装ros2
  5. JavaFX 中使用多线程与保证 UI 线程安全
  6. linux培训机构 网络班,Linux基础教程之网络基础知识与Linux网络配置
  7. HDCMS导航高亮显示!解决办法
  8. 前端学习(2571):为什么使用vuex
  9. Android studio 报错:Manifest merger failed xxx
  10. 基于主动学习算法减少人工标注量,提升文本标注效率的方案探究
  11. lol最克制诺手的英雄_LOL:究竟有没有完美克制诺手的英雄?时光上单或可一战?...
  12. 西餐美食店响应式网站模板
  13. JavaScript学习(五十二)—继承、call方法和apply方法
  14. WCF走你~一个简单的例子,根据用户ID,从用户模块(用户服务器)获得实体
  15. IP defragment
  16. MPQ4420HGJ DCDC电源设计+SIMetrix+Spice仿真模型
  17. 生物信息学常用数据库
  18. 【网络】Select服务器的实现
  19. 前端实现导入PPT在线编辑
  20. 输入验证码,一直报错验证码错误(内网多服务器)

热门文章

  1. 华夏教师杂志华夏教师杂志社华夏教师编辑部2022年第24期目录
  2. mysql定时任务,把7天的数据存到历史表,再删除7天前的数据
  3. 经典合成器和键盘合集-Arturia V Collection 7 v7.1.2 WiN
  4. 拆解SSK SCRM330 USB3.0读卡器 GL3233 固件 0819
  5. 数据库应用——DQL查询数据(连表查询 子查询 详细案例)
  6. 优测云服务平台分享开源自动化测试框架,快快get起来
  7. 2018清明假期旅游预测报告:全国游客人次预计破亿
  8. 生物特性再次助力无人机技术突破
  9. 双向可控硅实现 插头防插拔火花
  10. Nginx Proxy Cache原理和最佳实践