当我点击发送按钮时,它不会发送任何消息 程序没有错误,请帮我解决这个问题。
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
QBChatMessage chatMessage = new QBChatMessage();
chatMessage.setBody(edtContent.getText().toString());
chatMessage.setSenderId(QBChatService.getInstance().getUser().getId());
chatMessage.setSaveToHistory(true);
try {
qbChatDialog.sendMessage(chatMessage);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
QBChatMessagesHolder.getInstance().putMessage(qbChatDialog.getDialogId(), chatMessage);
ArrayList<QBChatMessage> messages = QBChatMessagesHolder.getInstance().getChatMessagesByDialogId(qbChatDialog.getDialogId());
adapter = new ChatMessageAdapter(getBaseContext(), messages);
lstChatMessages.setAdapter(adapter);
adapter.notifyDataSetChanged();
答案 0 :(得分:0)
我在我的应用中使用了快速blox sdk。下面是发送消息及其工作正常的代码。
private void sendChatMessage(String text) {
QBChatMessage chatMessage = new QBChatMessage();
chatMessage.setBody(text);
chatMessage.setProperty(PROPERTY_SAVE_TO_HISTORY, "1");
chatMessage.setDateSent(System.currentTimeMillis() / 1000);
try {
if (Network.isNetworkConnected(ChatActivity.this)) {
chatDialog.sendMessage(chatMessage);
showMessage(chatMessage);
messageEditText.setText("");
checkIfOpponentIsOnline(chatMessage.getBody());
} else {
ToastUtil.showShortToast(ChatActivity.this, "Please check Internet connection and Try again");
}
} catch (SmackException e) {
Log.e(TAG, "Failed to send a message", e);
ToastUtil.showShortToast(ChatActivity.this, R.string.chat_send_message_error);
} catch (Exception e) {
Log.e(TAG, "Failed to send a message", e);
}
}
如果您仍然遇到问题,则必须检查Quickblox控制台上的dialogId和dialogUsers。肯定有问题。检查对话框中是否存在用户。如果没有您赢得的会话也无法发送任何消息,请检查ChatService会话原因。