0

我正在为我的聊天应用程序使用 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): 在 org.jivesoftware.smackx.ServiceDiscoveryManager.discoverInfo(ServiceDiscoveryManager.java:600) 10-10 08:55:12.458: W/System.err(1821):在 org.jivesoftware.smackx.ServiceDiscoveryManager.discoverInfo(ServiceDiscoveryManager.java:552) 10-10 08:55:12.478: W/System.err(1821): 在 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>
4

2 回答 2

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;
      }
于 2014-10-10T10:30:54.193 回答
0

这样做

替换此行

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

有了这个

RoomInfo roomInfo=MultiUserChat.getRoomInfo(connection,"VjNewMoiosandroid@conference.chat");
于 2014-10-10T09:30:22.890 回答