Java – asmack – receive custom XML messages||
I spent some time adding smack to my Android device Providers, my application receives it well I added the default iqproviders and extensionproviders, but I also added my custom extensionprovider, which is the following:
<extensionProvider> <elementName>players</elementName> <namespace>@R_402_2419@er:players</namespace> <className>company.games.@R_402_2419@er.PlayerListProvider</className> </extensionProvider>
I'd also like to introduce the playerlistprovider class. At present, it's just to see if it will be called (it won't be called) – when I know it will be called, I will fully implement it, so it's at least part of the function:
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"; } }
When I run the client Android application, I receive the following message:
<message to="eee@localhost" type="chat" id="9" from="admin@localhost"> <body> <players xmlns="@R_402_2419@er:players" command="playerlist"> <player>test1</player> <player>test2</player> </players> </body> <thread>3P0i00</thread> </message>
My question now is why the playerlistprovider (embeddedextensionprovider) is not called when a message is received The message contains tags and has @ R_ 402_ 2419@er : the namespace of the player, as I did in smack As specified in providers
Any ideas?
Solution
After reading similar questions on so, I came across question / answer and blog post about other way (Part 1) (Part 2) to realize custom message sending / receiving
Have you considered using packetextensionprovider instead of embeddedextensionprovider?
If you are interested in trying it out instead of the embeddedextensionprovider, you can explain it in more detail here It may not be what you are looking for... (it seems that it needs more manual parsing methods), but it may recognize your playerlistprovider class (by extending the pevent class.)