不能得到的XMPP服务器在Android上的公共房间列表? [英] Cannot get list of public rooms from xmpp Server on Android?

查看:255
本文介绍了不能得到的XMPP服务器在Android上的公共房间列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我是新来的Andr​​oid和我目前停留在此。 我必须要返回的XMPP服务器上创建公共房间列表。我遇到的问题是,code以下正常工作的Java,但有一个空指针异常的情况下,Android系统。 任何有关这帮助将是AP preciated。

我正在使用的Openfire服务器,并在本地计算机上测试它,这就是为什么我使用,而不是域名IP地址的原因。

我使用了JAVA和Asmack库Android版

嫌库

 字符串服务器名=192.168.3.113;
    ConnectionConfiguration配置=新ConnectionConfiguration(
            服务器名,5222);
    XMPPConnection连接=新XMPPConnection(配置);
    尝试 {
        connection.connect();

        connection.login(S1,123);

        收藏< HostedRoom>客房= MultiUserChat.getHostedRooms(
                连接,conference.geekoid);
        对于(HostedRoom房间:房间){
            的System.out.println(room.getName());
        }

    }赶上(XMPPException E){
        的System.out.println(错误+ e.getMessage()+\ N); //为JAVA
                    log.e(Android的错误,e.getmessage()); //为Android
    }
 

解决方案

我已经找到了解决问题的办法。

Android的asmack库使用此 getHostedRooms(接口连接,             字符串服务名)方式

  ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(连接);
 

我用它代替

  ServiceDiscoveryManager discoManager =新ServiceDiscoveryManager(连接);
 

对于那些谁感到困惑的地方这种方法是其在

套​​餐:org.jivesoftware.smackx.muc

文件:MultiUserChat.java

在你这样做。我们必须要注册的详细信息可以在这里找到 所有供应商的Andr​​oid。这些供应商都在使用Java的咂嘴库(在Java开发中)自动注册,但在Android中,我们必须将它们注册我们自己。

Hello Everyone i am new to android and i am currently stuck on this. I have to return list of public rooms created on xmpp server. The problem i am having is that the code below works fine for java but there is a null pointer exception in case of android. Any help regarding this would be appreciated.

I am using an openfire server and testing it on local machine so that is the reason why i am using ip Address instead of domain name.

I am using smack library for JAVA and Asmack Library for android

String server_name = "192.168.3.113";
    ConnectionConfiguration config = new ConnectionConfiguration(
            server_name, 5222);
    XMPPConnection connection = new XMPPConnection(config);
    try {
        connection.connect();

        connection.login("s1", "123");

        Collection<HostedRoom> rooms = MultiUserChat.getHostedRooms(
                connection, "conference.geekoid");
        for (HostedRoom room : rooms) {
            System.out.println(room.getName());
        }

    } catch (XMPPException e) {
        System.out.println("Error" + e.getMessage() + "\n"); //for JAVA
                    log.e("Android Error",e.getmessage());  // For Android
    }

解决方案

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.

这篇关于不能得到的XMPP服务器在Android上的公共房间列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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