如标题描述,以下是相关代码,
<code>
final List clientIds = new ArrayList();
clientIds.add("yaniup");
clientIds.add("flover");
// 常量定义:
// int ConversationType_OneOne = 0; // 两个人之间的单聊
// int ConversationType_Group = 1; // 多人之间的群聊
final Map attr = new HashMap();
attr.put("type", 0);
final AVIMClient user = AVIMClient.getInstance(userNameString);
user.open(new AVIMClientCallback() {
@Override
public void done(AVIMClient client, AVIMException e) {
Log.e("client login status",client.getClientId()+" login successfully!");
user.createConversation(clientIds, attr, new AVIMConversationCreatedCallback() {
@Override
public void done(AVIMConversation conversation, AVIMException e) {
if (conversation!=null)
{
Intent jumpChatPage = new Intent(LoginPage.this, ChatPage.class);
jumpChatPage.putExtra("user_name",userNameString);
jumpChatPage.putExtra("conversation_id",conversation.getConversationId());
startActivity(jumpChatPage);
}
}
});
}
});
发送消息代码
AVIMTextMessage textMessage = new AVIMTextMessage();
textMessage.setText(chatEdit.getText().toString().trim());
if (avimConversation!=null)
{
avimConversation.sendMessage(textMessage, new AVIMConversationCallback() {
@Override
public void done(AVIMException e) {
Log.e("msg status"," been sent!");
}
});
}
else
Log.e("avimConversation"," is null");
通过sendMessage发送消息,双方都无法从回调函数中获取消息,但是通过后台发送消息,可以在回调函数中得到消息,第一次使用leancloud,麻烦知道的帮帮忙,先谢谢了