如何使用 Smack 接收传入的 XMPP 消息? [英] How to receive Incoming XMPP Messages using Smack?

查看:46
本文介绍了如何使用 Smack 接收传入的 XMPP 消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了一些示例并对其进行了测试,但所有示例都需要先与某人开始聊天才能接收传入消息...我想检索此传入消息而无需先与 jid 交谈任何人都可以举个例子吗?

I read some examples and tested them but all of them need to start a chat with someone first to receive Incoming Messages... I want to retrieve this Incoming Messages without need to talk first to the jid anyone can give an example ?

推荐答案

您需要注册一个 ChatListener 才能收到新聊天的通知,然后您可以像往常一样为其添加消息监听器:

You need to register a ChatListener to be notified of new chats, then you can add a message listener to them like normal:

connection.getChatManager().addChatListener(new ChatManagerListenerImpl());

....

private class ChatManagerListenerImpl implements ChatManagerListener {

    /** {@inheritDoc} */
    @Override
    public void chatCreated(final Chat chat, final boolean createdLocally) {
        chat.addMessageListener(...);
    }

}

这篇关于如何使用 Smack 接收传入的 XMPP 消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆