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);
}
Each MultiUserChat needs to add a Listener like this:
MultiUserChat muc = MultiUserChatManager.getInstanceFor(mConnection).getMultiUserChat( mucJid );
muc.addMessageListener(new MessageListener()...);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.