android项目中集成融云IM之实现消息提供者来显示群名

来源:互联网 发布:php mysql web 编辑:程序博客网 时间:2024/05/16 16:10

        融云的消息提供者可以用来设置群名,昵称,头像等等。由于套路都是一样的,正好现在做到显示群名这块。所以就说说这个,其他消息提供者跟这个是大同小异。


思路:

1.创建一个类,集成群组信息接口GroupInfoProvider

2.注册监听器,RongIM.setGroupInfoProvider(this, true);

3.重写getGroupInfo()方法,返回Group(id,name,image),这三个参数要对应。参数来源:从你的Server中获取数据来填入


下面附上源码:由于其他消息提供者的实现是类似的,这个类可以直接参考

public class IMAPPContext implements RongIM.GroupInfoProvider{    private Context context;    private static IMAPPContext imcontext;    public IMAPPContext(Context context) {        this.context = context;        new ShowGroupData(context);        initListener();    }    public static void init(Context context) {        if (imcontext == null) {            synchronized (IMAPPContext.class) {                if (imcontext == null) {                    imcontext = new IMAPPContext(context);                }            }        }    }    private void initListener() {        RongIM.setGroupInfoProvider(this, true);    }    @Override    public Group getGroupInfo(String s) {        if(ShowGroupData.findGroupData_beanList!=null){            for (FindGroupData_Bean f:ShowGroupData.findGroupData_beanList){                if(f.getGroupid().equals(s)){                    return new Group(f.getGroupid(), f.getGroupname(),null);                }            }        }        return null;    }}




0 0
原创粉丝点击