我正在使用smack libary开发聊天应用程序。我在群聊中有问题。在我的应用程序中,我正在创建组,并且成员是自动加入的。我想在组中发送消息时通知所有用户,即使他们还没有发起聊天。我的代码如下,我在init方法中放置了监听器但是无法收到消息。
//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);
}
答案 0 :(得分:0)
每个MultiUserChat都需要添加一个这样的监听器:
then(...)