Raj
Raj

Reputation: 864

Unable to get xmpp muc room information in android

I am using asmack library for my chat application.I am using below described code after successful login for getting Muc room information:

MultiUserChat mMultiUserChat = new MultiUserChat(connection,"[email protected]");
mMultiUserChat.join(USERNAME);
try {     
  if (mMultiUserChat.isJoined()==true) {                                  
  RoomInfo roomInfo=mMultiUserChat.getRoomInfo(connection,"[email protected]");}

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

                              e.printStackTrace();
                          }

I get this error while getting room information ,while i debug and check i am getting room information in log but nothing comes in roomInfo.

10-10 08:55:12.388: W/System.err(1821): java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2 cannot be cast to 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)

My chat room information i received in log

10-10 15:38:10.133: D/SMACK(26035): 03:38:10 PM RCV  (1107887640): <iq 
from='[email protected]' 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>

Upvotes: 0

Views: 900

Answers (2)

Raj
Raj

Reputation: 864

I was using old asmack jar that is my issue ,I made some changes i used MultiUserChat class getRoomInfo() Method directly in my class

MultiUserChat mMultiUserChat = new MultiUserChat(connection,"[email protected]");
mMultiUserChat.join(USERNAME);
try {     
  if (mMultiUserChat.isJoined()==true) {                                  
  String roomInfo=getRoomInfo(connection, "[email protected]");}

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

                              e.printStackTrace();
                          }

I made one method as below

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;
      }

Upvotes: 1

Biraj Zalavadia
Biraj Zalavadia

Reputation: 28484

Do this way

Replace this line

RoomInfo roomInfo=mMultiUserChat.getRoomInfo(connection,"[email protected]");

With this

RoomInfo roomInfo=MultiUserChat.getRoomInfo(connection,"[email protected]");

Upvotes: 0

Related Questions