无法在android中获取xmpp muc房间信息

时间:2014-10-10 09:15:28

标签: xmpp ejabberd asmack multiuserchat

我正在为我的聊天应用程序使用asmack库。我在成功登录后使用下面描述的代码来获取Muc房间信息:

MultiUserChat mMultiUserChat = new MultiUserChat(connection,"VjNewMoiosandroid@conference.chat");
mMultiUserChat.join(USERNAME);
try {     
  if (mMultiUserChat.isJoined()==true) {                                  
  RoomInfo roomInfo=mMultiUserChat.getRoomInfo(connection,"VjNewMoiosandroid@conference.chat");}

                          } catch (Exception e) {
                              // TODO: handle exception

                              e.printStackTrace();
                          }

我在获取房间信息时收到此错误,而我调试并检查我在日志中获取房间信息但房间信息中没有任何内容。

  

10-10 08:55:12.388:W / System.err(1821):java.lang.ClassCastException:   org.jivesoftware.smack.util.PacketParserUtils $ 2无法转换为   org.jivesoftware.smackx.packet.DiscoverInfo 10-10 08:55:12.428:   W / System.err(1821):at   org.jivesoftware.smackx.ServiceDiscoveryManager.discoverInfo(ServiceDiscoveryManager.java:600)   10-10 08:55:12.458:W / System.err(1821):at   org.jivesoftware.smackx.ServiceDiscoveryManager.discoverInfo(ServiceDiscoveryManager.java:552)   10-10 08:55:12.478:W / System.err(1821):at   com.demo.xmppchat.CopyOfXMPPChatDemoActivity.getRoomInfo(CopyOfXMPPChatDemoActivity.java:469)

我在日志中收到的聊天室信息

10-10 15:38:10.133: D/SMACK(26035): 03:38:10 PM RCV  (1107887640): <iq 
from='VjNewMoiosandroid@conference.chat' to='14393671556301070000@chat/Smack' 
id='VWaeO-6' type='result'><query xmlns='http://jabber.org/protocol/disco#info'><identity 
category='conference' type='text' name='VjNewMoiosandroid'/><feature var='
http://jabber.org/protocol/muc'/><feature var='muc_public'/><feature 
var='muc_persistent'/><feature var='muc_open'/><feature var='muc_semianonymous'/><feature 
var='muc_moderated'/><feature var='muc_unsecured'/><x xmlns='jabber:x:data' 
type='result'><field type='hidden' var='FORM_TYPE'><value>
http://jabber.org/protocol/muc#roominfo</value></field><field label='Room description' 
var='muc#roominfo_description'><value></value></field><field label='Number of occupants' 
var='muc#roominfo_occupants'><value>1</value></field></x></query></iq>

2 个答案:

答案 0 :(得分:1)

我使用的是旧的asmack jar,这是我的问题,我做了一些更改,我在我的班级中直接使用MultiUserChat类getRoomInfo()方法

MultiUserChat mMultiUserChat = new MultiUserChat(connection,"VjNewMoiosandroid@conference.chat");
mMultiUserChat.join(USERNAME);
try {     
  if (mMultiUserChat.isJoined()==true) {                                  
  String roomInfo=getRoomInfo(connection, "VjNewMoiosandroid@conference.chat");}

                          } catch (Exception e) {
                              // TODO: handle exception

                              e.printStackTrace();
                          }

我做了一个方法如下

public static String getRoomInfo(Connection connection, String room)
              throws XMPPException {
       String roomInfo="";
       try {
            ServiceDiscoveryManager serviceDiscoveryManager=new ServiceDiscoveryManager(connection);
            DiscoverInfo info = serviceDiscoveryManager.discoverInfo(room);
            roomInfo=info.toXML();

      } catch (XMPPException e) {
          // TODO: handle exception
          Log.e("xmpp", e.toString());

      }

          return  roomInfo;
      }

答案 1 :(得分:0)

这样做

替换此行

RoomInfo roomInfo=mMultiUserChat.getRoomInfo(connection,"VjNewMoiosandroid@conference.chat");

有了这个

RoomInfo roomInfo=MultiUserChat.getRoomInfo(connection,"VjNewMoiosandroid@conference.chat");