aSmack MessageListener 的 processMessage 从未被调用

发布于 2024-12-28 11:29:05 字数 1116 浏览 4 评论 0原文

我正在尝试使用 aSmack 在 Android 手机之间设置 XMPP 通信的基础知识。我已成功从我的应用程序注册一个帐户,并将消息发送到我在 PC 上登录的 Jabber-ID。问题是我的 PC 客户端的回复似乎没有收到,我的 MessageListener 中的 processMessage() 似乎没有被调用。

       try{connection.login("kmomochesstest", "password1");}
       catch(Exception e){Log.e("connection","Account login error: " + e.toString());}
       chat = connection.getChatManager().createChat("[email protected]", new MessageListener() {

             public void processMessage(Chat chat, Message message) {
                 try{System.out.println(message.getBody());}
             catch(Exception e){Log.e("connection","Message send error: " + e.toString());}
       });
       try{chat.sendMessage("Test Message from Activity");Log.d("connection","Just sent Message ");}
        catch(Exception e){Log.e("connection","Message send error: " + e.toString());}

此时,我正在尝试打印到控制台,但我尝试打印到日志并使用 chat.sendMessage(message.getBody()) 回显到我的电脑。似乎没有任何东西可以注册传入的消息。这似乎是我在网上找到的所有操作指南的格式。

I am trying the basics of setting up XMPP communication between android phones using aSmack. I have managed to register an account from my app and send messages to a Jabber-ID that I'm logged into on my PC. The issue is replies from my PC client don't seem to be getting received, the processMessage() in my MessageListener doesn't seem to be being called.

       try{connection.login("kmomochesstest", "password1");}
       catch(Exception e){Log.e("connection","Account login error: " + e.toString());}
       chat = connection.getChatManager().createChat("[email protected]", new MessageListener() {

             public void processMessage(Chat chat, Message message) {
                 try{System.out.println(message.getBody());}
             catch(Exception e){Log.e("connection","Message send error: " + e.toString());}
       });
       try{chat.sendMessage("Test Message from Activity");Log.d("connection","Just sent Message ");}
        catch(Exception e){Log.e("connection","Message send error: " + e.toString());}

At this point I'm trying to print to the console but I've tried printing to the Log and just echoing back to my PC with chat.sendMessage(message.getBody()). Nothing seems to register an incoming message. This seems to be the format on every how-to I've found online.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹏半生如梦愿梦如真 2025-01-04 11:29:05

您使用什么版本的 Smack?

在早期版本中,当尝试将不包含线程 ID 的消息与使用线程 ID 创建的现有聊天进行匹配时(如 Smack 所做的那样),会出现问题。例如,Pidgin 不使用线程 ID,而线程 ID 会在收到消息时创建一个新的聊天实例。

3.2 中对匹配过程进行了改进,以防止这种情况发生。

尝试创建一个 ChatManagerListener 并查看是否从您的回复中创建了新的聊天。

What version of Smack are you using?

There was a problem in earlier versions when trying to match messages that did not contain thread ids to existing chats that were created with one (as Smack does). Pidgin, for instance does not use thread id's, which would in turn create a new chat instance when a message was received.

The matching process was improved in 3.2 to prevent this from happening.

Try creating a ChatManagerListener and see if you are getting new Chat's created from your replies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文