Cannot get list of public rooms from xmpp Server on Android?

若如初见. 提交于 2019-11-30 10:28:57

The problem is that the static block of the ServiceDiscoveryManager class has to be evaluated before any connection is created. In smack this is done via an configuration file, but this approach does not work on Android and therefore on aSmack.

The workaround mentioned in the answer is somehow ugly, since you really don't want to use the Constructor to fetch the SDM object, instead the get() method should be used. But the get() method only works if there was actually a SDM created for the connection.

So in order to init the SDM correctly on Android you need to call the full forName notation to init the static blocks of the class before you create the first (XMPP)Connection object.

Class.forName("org.jivesoftware.smackx.ServiceDiscoveryManager", true, ClassLoader.getSystemClassLoader()):

This is tracked as aSmack Issue 8

I have found the Solution to the problem.

The Android asmack library was using this in getHostedRooms(Connection connection, String serviceName) method

ServiceDiscoveryManager discoManager =ServiceDiscoveryManager.getInstanceFor(connection);

i replaced it with

ServiceDiscoveryManager discoManager = new ServiceDiscoveryManager(connection);

For those who are confused where this method is its in

Package: org.jivesoftware.smackx.muc

File: MultiUserChat.java

After you have done this. We have to register all the providers in Android whose detail can be found here. These providers are automatically registered when are using JAVA's smack library (In java Development) but in Android we have to register them ourself.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!