有兩個用戶A和B。如何從openfire聊天記錄一對一聊天
- 首先登錄並且B已經離線。
- A發送消息至B。
- 現在乙是要在線但無法得到的消息是什麼一個 已發送到乙。
- 如果甲和乙同時在不同的設備都記錄和 兩者聊天然後消息發送和接收是完全完成 。
幫助我如何獲得一對一聊天的聊天記錄?
這是發送消息:
public void sendTextMessage(View v) {
String message = msg_edittext.getEditableText().toString();
if (!message.equalsIgnoreCase("")) {
final ChatMessage chatMessage = new ChatMessage(user1, user2,
message, "" + random.nextInt(1000), false);
chatMessage.setMsgID();
chatMessage.body = message;
chatMessage.Date = CommonMethods.getCurrentDate();
chatMessage.Time = CommonMethods.getCurrentTime();
msg_edittext.setText("");
chatAdapter.add(chatMessage);
chatAdapter.notifyDataSetChanged();
//MainActivity activity = ((MainActivity) context);
getmService().xmpp.sendMessage(chatMessage);
}
}
public void sendMessage(ChatMessage chatMessage)
{
String body = gson.toJson(chatMessage);
if (!chat_created)
{
Mychat = ChatManager.getInstanceFor(connection).createChat(
chatMessage.receiver + "@"
+ "sspl163",
mMessageListener);
chat_created = true;
}
final Message message = new Message();
message.setBody(body);
message.setStanzaId(chatMessage.msgid);
message.setType(Message.Type.chat);
try {
if (connection.isAuthenticated())
Mychat.sendMessage(message);
else
login();
}
catch (NotConnectedException e) {
Log.e("xmpp.SendMessage()", "msg Not sent!-Not Connected!");
}
catch (Exception e) {}
}
這是用於檢索信息:
private class MMessageListener implements ChatMessageListener
{
public MMessageListener(Context contxt) {}
@Override
public void processMessage(final org.jivesoftware.smack.chat.Chat chat, final Message message)
{
if (message.getType() == Message.Type.chat && message.getBody() != null)
{
final ChatMessage chatMessage = gson.fromJson(message.getBody(), ChatMessage.class);
processMessage(chatMessage);
}
}
private void processMessage(final ChatMessage chatMessage)
{
chatMessage.isMine = false;
SharedPreferences shared = context.getSharedPreferences("MyPREFERENCES", MODE_PRIVATE);
String user = (shared.getString("username", ""));
if(chatMessage.receiver.equalsIgnoreCase(user) && Chats.user2.equalsIgnoreCase(chatMessage.sender))
Chats.chatlist.add(chatMessage);
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Chats.chatAdapter.notifyDataSetChanged();
}
});
}
}
您的問題是'沒有得到用戶B的離線消息'對嗎? –
是的,B無法獲得消息 –
檢查您的openfire設置作爲我的答案。 –