注册

扩展信息怎么弄的,接口在哪里?-Android端?

扩展信息怎么弄的,接口在哪里?-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即可取到这些value
private class NewMessageBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// 消息id
String msgId = intent.getStringExtra("msgid");
//根据消息id获取message
EMMessage 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);
}
}



要回复问题请先登录注册