Java – smack status listener in multi-user chat

smack status listener in multi-user chat… here is a solution to the problem.

smack status listener in multi-user chat

The smack status listener in a multi-user chat is not called. Log in using the Smack API and add roster.addRosterListener(mRoasterListener); However, when the presence of other users in the chat room changes, it cannot be successfully listened to. I tried the following code to get the presence listener to work:

connection.login(loginUser, passwordUser);

MultiUserChatManager manager = 


muc = manager.getMultiUserChat(roomID + "@" +context.getString(R.string.group_chat_id));

Log.d("Join User: ", "Already Created");



Roster roster = Roster.getInstanceFor(connection);//luna


Log.d("Joined User Phone: ", " " + Utilities.getUserPhoneNo(context));

This class is used to listen for changes in presence….

public class RoasterListener implements RosterListener{
        public RoasterListener(Context context){


        public void entriesAdded(Collection<String> collection) {


        public void entriesUpdated(Collection<String> collection) {


        public void entriesDeleted(Collection<String> collection) {


        public void presenceChanged(Presence presence) {
            System.out.println("Presence changed: " + presence.getFrom() + " " + presence);

I tried many of the links provided by StackOverflow without success.
Please help!


For multi-user chats, you don’t have to use a roster because it’s normal to meet someone who isn’t on the roster.

To know who is in the MUC, first ask the occupants:


List<String> occupantsAtJoinTime = muc.getOccupants();

for (String occupant : occupantsAtJoinTime)
                        System.out.println("occupant: "+occupant);

Then, to update the Occupants list, register a DefaultParticipantStatusListener with your muc and define the Listner:

muc.addParticipantStatusListener(new CustomParticipantStatusListner());

Defined as (there are many ways to implement it as needed):

    public class CustomParticipantStatusListner extends DefaultParticipantStatusListener 

public void joined(String participant) 
            System.out.println(participant + "just joined MUC");
actions (add occupantsRightNow)

public void left(String participant)
            System.out.println(participant + " just left MUC");
actions (remove occupantsRightNow)

All this with smack 4.1.7

Related Problems and Solutions