0

I am developing chat app using smack libary. I have issue in group chat. In my app i am creating group and in that members are auto joined.i want to notify all user when i send message in group even if they had not initiated chat.My code is as follow in that i have place listener in init method but unable to receive message.

 //Initialize
public void init(String userId, String pwd, Context context) throws SmackException.NotConnectedException {
    this.mUserName = userId;
    this.mPassWord = pwd;
    this.mContext = context;

    sessionManager = new SessionManager(context);

    if (userId.contains("@")) {
        this.mUserName = userId.split("@")[0];
    }
    XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
    configBuilder.setUsernameAndPassword(mUserName, mPassWord);
    configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
    configBuilder.setServiceName(XMPPCredential.SERVICE);
    configBuilder.setHost(XMPPCredential.HOST);
    configBuilder.setPort(XMPPCredential.PORT);
    configBuilder.setResource("");
//        configBuilder.setDebuggerEnabled(true);


    mConnection = new XMPPTCPConnection(configBuilder.build());
    PingManager pingManager = PingManager.getInstanceFor(mConnection);
    pingManager.setPingInterval(300); // 2.5 min
    pingManager.registerPingFailedListener(this);

    mChatmanager.getInstanceFor(mConnection).addChatListener(this);

    multiUserChatManager = MultiUserChatManager.getInstanceFor(mConnection);
    mConnection.addAsyncStanzaListener(this, null);
    mConnection.addSyncStanzaListener(this,null);

    ReconnectionManager.getInstanceFor(mConnection).enableAutomaticReconnection();
    mConnection.addConnectionListener(this);

    // Connect with XMPP server
    connectConnection(context);
}
Jinal Patel
  • 699
  • 5
  • 15

1 Answers1

0

Each MultiUserChat needs to add a Listener like this:

MultiUserChat muc =  MultiUserChatManager.getInstanceFor(mConnection).getMultiUserChat( mucJid );

muc.addMessageListener(new MessageListener()...);
MrPk
  • 2,862
  • 2
  • 20
  • 26
  • how would we know mucJid if there are more than one Room? mucJid will be different in this case right? In my point of view we need to play with stanza tags. – Fakhar Dec 18 '18 at 12:25