本文介绍了短信发送状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用smack和openfire在android中创建聊天应用.对于消息状态,我在其他消息中传递和显示的消息没有问题客户(仔细检查).我将像波纹管这样的简单json消息发送给发件人: {交付":timestapmp} 并对其进行解析,并仔细检查消息是否具有低于之前发送的时间戳的消息.问题在于发送状态(一次检查).当我发送消息时,服务器未响应该消息已发送的任何内容.是否有可能通过服务器发送带有回调的消息.如果可能,是否可以在回调响应中发送时间服务器.谢谢.

I am using smack and openfire for create chat app in android .for message status I have no problem with delivered and displayed message in otherclient (double check).I will send a simple json message like bellow to sender: {"delivery":timestapmp} and parse it and double check messages with lower than timestamp that sent before.the problem is about sent status (one check).When i send message the server no response anything that message has sent .is it possible in smack to send message with callback from server.if possible and is it possible to send time server in callback response .thanks .

推荐答案

private void acknowledgementFromServer(final Message message) throws StreamManagementException.StreamManagementNotEnabledException {
        if (connection != null && connection.isSmEnabled()) {
            connection.addStanzaIdAcknowledgedListener(message.getStanzaId(), new StanzaListener() {
                @Override
                public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {

                        MessageAsyncTask task = new MessageAsyncTask(packet.getStanzaId(), MSG_STATUS_SENT);
                        task.execute();

                }
            });
        }

嘿,每次发送消息时,您都可以通过在上述方法中将该消息作为参数传递来做到这一点.

Hey you can do it like this.. call method every time you send message by passing that message as a parameter in above method

注意:应启用流管理才能使其正常工作,可以通过以下方式完成:

Note: Stream Management should be enabled for this to work, can be done like below:

DeliveryReceiptManager.setDefaultAutoReceiptMode(DeliveryReceiptManager.AutoReceiptMode.always);
        ProviderManager.addExtensionProvider(DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE, new DeliveryReceipt.Provider());
        ProviderManager.addExtensionProvider(DeliveryReceiptRequest.ELEMENT, DeliveryReceipt.NAMESPACE, new DeliveryReceiptRequest.Provider());

这篇关于短信发送状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 14:50