Android 环信 扩展消息实现昵称头像的同步 点击头像跳转到主页所需的user_id等参数 消息列表的头像和昵称同步数据等

扩展消息实现昵称头像的同步 点击头像跳转到主页所需的user_id等参数

步骤一:将数据传递给EaseChatFragment,如图中的user_name等。

在这里插入图片描述
步骤二:在EaseChatFragment中的sendMessage方法中设置扩展消息,如图:
在这里插入图片描述
步骤三:在EaseChatRow中设置收到消息的地方,设置昵称等信息,如图:

在这里插入图片描述

消息列表的头像和昵称的设置:

步骤一:

收到消息时,将昵称头像和用户id转成json字符串,通过环信的自定义会话拓展方法setExtField,保存到本地。修改DemoHelper中的onMessageReceived方法代码如下:

 @Override
            public void onMessageReceived(List<EMMessage> messages) {
                for (EMMessage message : messages) {
                    EMLog.d(TAG, "onMessageReceived id : " + message.getMsgId());

                    // 判断一下是否是会议邀请
                    String confId = message.getStringAttribute(Constant.MSG_ATTR_CONF_ID, "");
                    if (!"".equals(confId)) {
                        String password = message.getStringAttribute(Constant.MSG_ATTR_CONF_PASS, "");
                        String extension = message.getStringAttribute(Constant.MSG_ATTR_EXTENSION, "");
                        goConference(confId, password, extension);
                    }
                    // in background, do not refresh UI, notify it in notification bar
                    if (!easeUI.hasForegroundActivies()) {
                        getNotifier().notify(message);
                    }

                    EMConversation conversation = EMClient.getInstance().chatManager().getConversation(message.getFrom(), EaseCommonUtils.getConversationType(EaseConstant.CHATTYPE_SINGLE), true);
                    JSONObject jsonObject = new JSONObject();
                    String nickname = message.getStringAttribute("user_name", "");
                    String avatar = message.getStringAttribute("photo_path", "");
                    String user_id_jump = message.getStringAttribute("user_id_jump", "");
                    //   String rank_id = message.getStringAttribute("rank_id", "");
                    try {
                        if (!TextUtils.isEmpty(nickname)) {
                            jsonObject.put("user_name", nickname);
                        }
                        if (!TextUtils.isEmpty(avatar)) {
                            jsonObject.put("photo_path", avatar);
                        }
                        if (!TextUtils.isEmpty(user_id_jump)) {
                            jsonObject.put("user_id_jump", user_id_jump);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                    conversation.setExtField(jsonObject.toString());

                }
            }

步骤二:在EaseConversationAdapter中设置保存下来的拓展字段的信息,如图:
在这里插入图片描述

发布了38 篇原创文章 · 获赞 11 · 访问量 8796

猜你喜欢

转载自blog.csdn.net/u013750244/article/details/102632565
今日推荐