0

I'm working on an Android app that utilizes ASmack to send XMPP messages to and from a server in a background service. I can join a MultiUserChat (MUC) by calling MultiUserChat.join(connection.getUser());. I can confirm that I joined the chat by calling MultiUserChat.isJoined();, which returns true. Also, since I'm using www.hosted.im, I can see that I am in the conference room using their online UI. In another function, I try to retrieve the list of joined rooms, using MultiUserChat.getJoinedRooms(connection, connection.getUser());, but that returns an empty iterator.

private XMPPConnection connection;

/*... Connect to server and login with username and password ...*/

public Iterator<String> getJoinedRooms() {
    Log.i(ChatListActivity.TAG, "Trying to get joined rooms");
    Iterator<String> result = null;
    if(connection != null) {
        Log.i(ChatListActivity.TAG, "Returning joined chat rooms as " + connection.getUser());
        result = MultiUserChat.getJoinedRooms(connection, connection.getUser());
        while(result.hasNext()) {
           Log.w(ChatListActivity.TAG, result.next());
        }
    } else {
        Log.e(ChatListActivity.TAG, "Cannot get joined rooms.  Connection == NULL");
    }

    if(result == null || (result != null && !result.hasNext())) {
        ArrayList<String> resultArr = new ArrayList<String>();
        resultArr.add(getString(R.string.no_chat_rooms_joined));
        result = resultArr.iterator();
        Log.i(ChatListActivity.TAG, "Returning EMPTY ITERATOR for joined chat rooms");
    }
    return result;
}

public void joinRoom(String room) {
    if(connection != null) {
        Log.i(ChatListActivity.TAG, "Joining room " + room);
        // Create a MultiUserChat using a Connection for a room
        MultiUserChat muc2 = new MultiUserChat(connection, "testroom@conference.konstadtest.p1.im");

        try {
            muc2.join(connection.getUser());
            muc2.grantVoice(connection.getUser());
            muc2.grantMembership(connection.getUser());
            if(muc2.isJoined())
                Log.w(ChatListActivity.TAG, "Joined room " + room + " as " + connection.getUser());
            else
                Log.w(ChatListActivity.TAG, "Failed to join " + room + " as " + connection.getUser());
        } catch (XMPPException e) {
            e.printStackTrace();
            Log.w(ChatListActivity.TAG, "Cannot join room " + room);
        }
    } else {
        Log.w(ChatListActivity.TAG, "Cannot join room " + room + " because connection is NULL");
    }
}

What am I doing wrong? I called SmackAndroid.init(getApplicationContext()); before calling anything else.

Thank you for the help,

Chris

  • It's hard to tell what's going wrong just from the code you posted. aSmack comes with sources, therefore I suggest you try to debug the problem. Having a look at the interchanged XMPP stanzas may also provide a hint. – Flow Jan 21 '14 at 09:18
  • Okay. Thanks for the pointer! I'll check those out. Also, thanks for the work on aSmack! – chriskon149 Jan 21 '14 at 17:59

1 Answers1

1

What i did is that i add a packet listener after getting get joined rooms.. i was also getting an empty list but when i debug i check that the rooms was getting returned in the resultant xml stanze that was sent by the server therefore i manually add ha packet listener like this:

public void AddPacketListener(){
    PacketFilter filter = new IQTypeFilter(IQ.Type.RESULT);
    MyService.getConnection().addPacketListener(new PacketListener() 
    {   
    public void processPacket(Packet paramPacket) {

    if(paramPacket.getFrom().equals(MyService.getConnection().getUser())){
            String xml=paramPacket.toXML();
            String from[];

            System.out.println(xml);
            from=paramPacket.getFrom().split("/");
                Pattern pattern = Pattern.compile("<item jid=\"(.*?)/>");
                Matcher matcher = pattern.matcher(xml);
                String parts[];

                Roomlist.clear();
                while (matcher.find()) {    

                    parts=matcher.group(1).split("@");
                    Roomlist.add(parts[0]);

                }      
                return;         
                }

    }
    },filter);

}
Fallak Asad
  • 368
  • 4
  • 18
  • hi , currently i am work on multiuserchat remove user and delete group thre are some problem when as admin delete or remove group member than all group member get notification but removed member not get notification in android or server side how to manage this please explain how to manage group leave , remove member and delete group listener in android. i am follow asmack example and only one muc or group object listener work. please help – Vijay Rajput Jul 05 '14 at 03:26
  • there are two types of listeners. one that listens for the notifications related to other members and other that listens for the user's own notifications. addUserStatusListener(UserStatusListener listener) listens for the user's own notification i.e. when he will be kicked or banned or when he is being grated any kind of permission. the other one is public void addParticipantListener(PacketListener listener) which listens for the other's notification. For more help you can ask. – Fallak Asad Jul 07 '14 at 05:48