asmack - 接收自定义 XML 消息 ||
我花了一些时间在 Android 设备中添加 smack.providers,我的应用程序可以很好地获取它。我已经添加了默认的 iqProviders 和 extensionProviders,但我还添加了自定义的 extensionProvider,如下所示:
<extensionProvider>
<elementName>players</elementName>
<namespace>boxer:players</namespace>
<className>company.games.boxer.PlayerListProvider</className>
</extensionProvider>
让我还介绍一下 PlayerListProvider 类,该类当前只是为了查看它是否会被调用(它不会被调用) t) - 当我知道它被调用时,我将完全实现它,因此至少这部分功能可以工作:
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.provider.EmbeddedExtensionProvider;
import android.util.Log;
@SuppressWarnings("deprecation")
class PlayerListProvider extends EmbeddedExtensionProvider {
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String,String> attributeMap, List<? extends PacketExtension> content) {
Log.w("***** AAAAAAAAAAAAAAAAAAAA *******", "0");
return new XMLPlayerList();
}
}
class XMLPlayerList implements PacketExtension {
public String getElementName() {
return "aaaaa";
}
public String getNamespace() {
return "aaaaa";
}
public String toXML() {
return "aaaaa";
}
}
当我运行客户端 android 应用程序时,我收到以下消息:
<message to="eee@localhost" type="chat" id="9" from="admin@localhost">
<body>
<players xmlns="boxer:players" command="playerlist">
<player>test1</player>
<player>test2</player>
</players>
</body>
<thread>3P0i00</thread>
</message>
我现在的问题是,为什么不不是 PlayerListProvider (EmbeddedExtensionProvider) 在收到消息时调用。该消息包含标签并具有 boxer:player 的命名空间,正如我在 smack.providers 中指定的那样。
有什么想法吗?
I've spend some time to add smack.providers in the android device, which is picked up by my application just fine. I've added the default iqProviders and extensionProviders, but I've also added my custom extensionProvider, which is the following:
<extensionProvider>
<elementName>players</elementName>
<namespace>boxer:players</namespace>
<className>company.games.boxer.PlayerListProvider</className>
</extensionProvider>
Let me also introduce the PlayerListProvider class, which is currently there just to see if it will get called (which it doesn't) - I'll implement it fully when I'll know it gets called, therefore at least that part of functionality works:
import java.util.List;
import java.util.Map;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smackx.provider.EmbeddedExtensionProvider;
import android.util.Log;
@SuppressWarnings("deprecation")
class PlayerListProvider extends EmbeddedExtensionProvider {
protected PacketExtension createReturnExtension(String currentElement, String currentNamespace, Map<String,String> attributeMap, List<? extends PacketExtension> content) {
Log.w("***** AAAAAAAAAAAAAAAAAAAA *******", "0");
return new XMLPlayerList();
}
}
class XMLPlayerList implements PacketExtension {
public String getElementName() {
return "aaaaa";
}
public String getNamespace() {
return "aaaaa";
}
public String toXML() {
return "aaaaa";
}
}
And I'm getting the following message when I run the client android app:
<message to="eee@localhost" type="chat" id="9" from="admin@localhost">
<body>
<players xmlns="boxer:players" command="playerlist">
<player>test1</player>
<player>test2</player>
</players>
</body>
<thread>3P0i00</thread>
</message>
My question now is, why isn't the PlayerListProvider (EmbeddedExtensionProvider) called upon receiving the message. The message contains the tag and has the namespace of boxer:player, as I specified in smack.providers.
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在阅读了有关 SO 的类似问题后,我遇到了这个 问题/answer 和这个 关于另一种方式的博客文章 (第 1 部分) (第 2 部分) 实现自定义消息发送/接收。
您是否考虑过使用 PacketExtensionProvider< /a> 代替 EmbeddedExtensionProvider?
此处有更详细的解释,如果您有兴趣尝试用它来代替
EmbeddedExtensionProvider
。它可能不完全是您正在寻找的...(看起来它需要更多的手动解析方法,)但它可能会让您的PlayerListProvider
类被识别(通过扩展 PEPEvent 类。)After reading about similar issues here on SO, I came across this question/answer and this blog post about another way (part 1) (part 2) to implement the custom message sending/receiving.
Have you considered using PacketExtensionProvider instead of EmbeddedExtensionProvider?
It's explained in more detail here, if you are interested in trying it out in place of the
EmbeddedExtensionProvider
. It might not be exactly what you are looking for... (it appears like it takes more of a manual-parsing approach,) but it might get yourPlayerListProvider
class recognized (via extending the PEPEvent class.)