【问题标题】:Send Message.Type.normal in smack XMPP android在 smack XMPP android 中发送 Message.Type.normal
【发布时间】:2017-06-14 07:16:36
【问题描述】:

我正在使用 Smack XMPP 创建一个聊天应用程序。除了读取/交付报告外,一切都运行良好。

这就是我发送交付报告的方式:

{
    Message message = new Message();
    message.setTo(chatMessage.getReceiver());
    message.setType(Message.Type.normal);
    message.setFrom(chatMessage.getSender());
    message.setStanzaId(chatMessage.getReceiver() + "_" + CommonMethods.getCurrentGMTTime(0));

    ChatMarker_File_XMPP_SERVER chatMarker_file_xmpp_server=new ChatMarker_File_XMPP_SERVER("received","urn:xmpp:chat-markers:0" , true);
    chatMarker_file_xmpp_server.setIdValue(chatMessage.getMsgid());
    message.addExtension(chatMarker_file_xmpp_server);
    Mychat = ChatManager.getInstanceFor(connection).createChat(
            message.getTo() + "@"
                    + context.getString(R.string.server),
            mMessageListener);
    try {
        if (connection.isAuthenticated()) {
            /********************************************************
             * ********    MESSAGE SEND     **********************
             ***/

           Mychat.sendMessage(message);

        } else {

            login();
        }
    } catch (SmackException.NotConnectedException e) {
        Log.e("xmpp.SendMessage()", "msg Not sent!-Not Connected!");

    } catch (Exception e) {
        Log.e("SendMessage()-Exception",
                "msg Not sent!" + e.getMessage());
    }

}

但问题是Mychat.sendMessage(message); SendMessage 方法正在这样做

 /**
     * Sends a message to the other chat participant. The thread ID, recipient,
     * and message type of the message will automatically set to those of this chat.
     *
     * @param message the message to send.
     * @throws NotConnectedException 
     */
    public void sendMessage(Message message) throws NotConnectedException {
        // Force the recipient, message type, and thread ID since the user elected
        // to send the message through this chat object.
        message.setTo(participant);
        message.setType(Message.Type.chat);
        message.setThread(threadID);
        chatManager.sendMessage(this, message);
    }

现在虽然我明确将“messageType”设置为“正常”,但“sendMessage()”再次将其转换为Type.Chat

我已经检查了其他可能的方法和文档,以便我可以通过 Type normal 发送一条消息,但找不到任何东西。

谢谢

【问题讨论】:

    标签: android xmpp smack


    【解决方案1】:

    为什么不使用交货收据管理器?

    发送消息时:

    Message message = new Message();
    String deliveryReceiptId = DeliveryReceiptRequest.addTo(message);
    message.setType(Message.Type.chat);
    

    您可以收到如下所示的送达确认..

    DeliveryReceiptManager.getInstanceFor(connection).addReceiptReceivedListener(new ReceiptReceivedListener() {
                        @Override
                        public void onReceiptReceived(Jid fromJid, Jid toJid, String receiptId, Stanza receipt) {
                            //here receiptId will be same as deliveryReceiptId u sent above which means msg is delivered to recipient 
                        }
                    });
                }
    

    如果您想将消息发送到服务器状态,您可以在此处查看我的答案: https://stackoverflow.com/a/44254615/6350239

    为了实现 msg 读取状态,您需要像这样https://stackoverflow.com/a/29001653/6350239 实现您的自定义阅读收据

    【讨论】:

      猜你喜欢
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-30
      • 1970-01-01
      • 2023-04-07
      • 2018-03-10
      相关资源
      最近更新 更多