我可以与openfire建立连接,但我无法发送或接收消息。以下是聊天代码
bt_send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
abc = et_message.getText().toString();
//Toast.makeText(getApplicationContext(), abc, Toast.LENGTH_SHORT).show();
ChatPojo cpojo = new ChatPojo(abc,true);
chatList.add(cpojo);
mAdapter.notifyDataSetChanged();
int position = chatList.size();
recyclerView.smoothScrollToPosition(position);
et_message.setText("");
Chat chat = ChatManager.getInstanceFor(connection).createChat(connection.getUser(), new ChatMessageListener() {
@Override
public void processMessage(Chat chat, Message message) {
Toast.makeText(getApplicationContext(),message.getBody(),Toast.LENGTH_SHORT).show();
}
});
Message message = new Message("admin2", Message.Type.chat);
message.setFrom("admin");
message.setBody(abc);
try {
chat.sendMessage(message);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}