问题描述
扩展信息怎么弄的,接口在哪里?-Android端?
解决方案
发普通消息的时候会带着扩展信息,接口文档http://easemob.com/docs/android/advanced/
解决方案二:
我也想知道,哈哈
解决方案三:
本帖最后由 chaoren 于 2015-2-27 13:24 编辑 SDK包含的数据类型只有语音,图片,文字,文件,视频,但是针对这几种并不能满足所有的app,环信提供的自定义扩展属性正好弥补了这个缺陷,你想做一个图文混排,名片等不同需求都可以很好的处理,举个制作名片的栗子private void sendUserCard() { EMMessage message = EMMessage.createSendMessage(EMMessage.Type.TXT);//名片消息依赖在文本类型上(也可以依赖在其它数据类型上) // 如果是群聊,设置chattype,默认是单聊 if (chatType == CHATTYPE_GROUP) message.setChatType(ChatType.GroupChat); TextMessageBody txtBody = new TextMessageBody(cardUser.getUsername()); message.addBody(txtBody); message.setAttribute("vCard", json对象); message.setReceipt(toChatUsername);conversation.addMessage(message);adapter.notifyDataSetChanged(); EMChatManager.getInstance().sendMessage(message, callback);//在接收消息的BroadcastReceive中,通过自己设置的key即可取到这些valueprivate class NewMessageBroadcastReceiver extends BroadcastReceiver {@Overridepublic void onReceive(Context context, Intent intent) {// 消息idString msgId = intent.getStringExtra("msgid"); //根据消息id获取messageEMMessage message = EMChatManager.getInstance().getMessage(msgId);//获取自定义的属性,第2个参数为返回的默认值String card = message.getStringAttribute("vCard",null);//判断card是否为空,如果不为空则为名片信息,如果为空则为普通信息abortBroadcast();}}private View createViewByMessage(EMMessage message, int position) {switch (message.getType()) {case IMAGE:return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_picture, null) : inflater.inflate(R.layout.row_sent_picture, null);case VOICE:return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_voice, null) : inflater.inflate(R.layout.row_sent_voice, null);default:String usercard = null;try {// 名片消息usercard = message.getStringAttribute("vCard");//根据usercard判断适配不同的布局} catch (EaseMobException e) {}if (usercard != null) {return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_card, null) : inflater.inflate(R.layout.row_sent_card, null);}return message.direct == EMMessage.Direct.RECEIVE ? inflater.inflate(R.layout.row_received_message, null) : inflater.inflate(R.layout.row_sent_message, null);}}