欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android-环信自定义消息

程序员文章站 2022-06-05 22:03:27
...
//此场景数据进入聊天界面自动发送订单,当然也可以选择订单发送,剩下的功能小伙伴们自己研究吧.文档很清晰的
//自定义一个发送消息体 我这边是一个类似于淘宝 京东电商订单的消息体,万变不离其宗
    private void sendOrderMessage() {
        EMMessage customMessage = EMMessage.createSendMessage(EMMessage.Type.CUSTOM);
        EMCustomMessageBody customBody = new EMCustomMessageBody("event");
        Map<String, String> params = new HashMap<>();
        params.put(EaseConstant.CS_DEC, "哈哈哈哈哈哈哈哈哈");
        params.put(EaseConstant.CS_TILE, "你好");
        params.put(EaseConstant.CS_IMG, "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1602407170086&di=0dab785fad253bc1f103a786171325c9&imgtype=0&src=http%3A%2F%2Fa3.att.hudong.com%2F14%2F75%2F01300000164186121366756803686.jpg");
        customBody.setParams(params);
        customMessage.addBody(customBody);
        customMessage.setTo(toChatUsername);
        sendMessage(customMessage);
    }
    
// 继承环信EaseUi EaseChatRow 如下:
public class EaseChatRowXXX extends EaseChatRow{
//重写以下方法
    @Override
    protected void onInflateView() {
		//获取自定义的布局
    }
        @Override
    protected void onFindViewById() {
    
    }
      @Override
    public void onSetUpView() {
        EMCustomMessageBody mBody = (EMCustomMessageBody) message.getBody();
        mBody.event();//这里event判断多种情况下的,与上面event相同
        Map<String, String> params = mBody.getParams();
     	//拿到自定义的body体 设置数据即可,与你发送的key一定要对应
    }
}