发送方
conversation.sendMessage(message, AVIMConversation.NONTRANSIENT_MESSAGE_FLAG, new AVIMConversationCallback()//发送消息,当用户不在时会进行推送
{
@Override
public void done(AVIMException e)
{
if (e == null)
{
subscriber.onCompleted();
} else
{
subscriber.onError(e);
}
}});
接收方的 handler
@Override
public void onMessage(AVIMMessage message, AVIMConversation conversation, AVIMClient client)
{
String clientId;
clientId = AVImClientManager.getInstance().getClientId();
if (client.getClientId().equals(clientId))
{
if (!message.getFrom().equals(clientId))
{
EventBus.getDefault().post(new EventHomeConversationChange(true, conversation));
}
}
}
此时这个 conversation 的 attr 为空。
这是我创建conversation 的代码
HashMap<String, Object> attr = new HashMap<String, Object>();
attr.put(ChatConstant.CHAT_TYPE, chatType);
client.createConversation(members, conversationName, attr, false, true, new
AVIMConversationCreatedCallback()
{
@Override
public void done(AVIMConversation avimConversation, AVIMException e)
{
if (e == null)
{
Logger.e("conversation create success");
subscriber.onNext(avimConversation);
} else
{
e.printStackTrace();
subscriber.onError(e);
}
}});
再次补充一下,只有当第一次创建会话,发送 message ,接收方的 conversation attr 才会为空。只有当重新拉取后台的 conversation 之后,接收方才能收到 attr。
debug显示:
此时后台的数据
麻烦了。。