gpt4 book ai didi

android - 如何从android获取smack或xmpp中消息的传递状态

转载 作者:搜寻专家 更新时间:2023-11-01 09:40:42 25 4
gpt4 key购买 nike

这是我的代码,我正在用这种方法发送消息,但无法在 DeliveryReceipt 中获取送达消息

    newChat.sendMessage(message);
newChat.getListeners();
newChat.addMessageListener(new ChatMessageListener() {
@Override
public void processMessage(Chat chat, Message message) {
Log.d(TAG,"DeliveryReceipt3:"+"1:"+message.getThread()+"2:"+chat.getThreadID()+"3:"+message.getBody());
}
});

上面的代码用于发送消息,下面的代码用于获取DeliveryReceipt

   Message m = new Message();
m.setType(Message.Type.chat);
m.setFrom(connection.getUser());
m.setTo(agentId);
m.addExtension(new DeliveryReceipt(m.getPacketID()));

DeliveryReceipt dr = (DeliveryReceipt)m.getExtension(DeliveryReceipt.ELEMENT, DeliveryReceipt.NAMESPACE);
Log.d(TAG,"DeliveryReceipt1: "+"1:"+dr.getElementName()+"2:"+dr.getId()+"3:"+dr.getNamespace()+"4:"+dr.toXML()+"4:"+dr.toString());
Log.d(TAG,"DeliveryReceipt2: "+"1:"+m.getBody()+"2:"+m.getStanzaId()+"3:"+m.getThread());

最佳答案

登录成功后需要添加DeliveryReceiptManager

DeliveryReceiptManager dm = DeliveryReceiptManager.getInstanceFor(connection);
dm.setAutoReceiptMode(AutoReceiptMode.always);
dm.autoAddDeliveryReceiptRequests();
dm.addReceiptReceivedListener(new ReceiptReceivedListener() {

@Override
public void onReceiptReceived(Jid fromJid, Jid toJid,
final String receiptId, Stanza receipt) {
// handle delivery receipt here
}
});

关于android - 如何从android获取smack或xmpp中消息的传递状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40045486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com