我在我的应用程序中使用开火但我无法检查我的用户是否已连接服务器请建议我如何检查。
答案 0 :(得分:-1)
检查这个给定的方法
public XMPPConnection connect(final String username, final String password,
final String host, final String service, final String port) {
// Create a connection
ConnectionConfiguration connConfig = new ConnectionConfiguration(host, Integer.parseInt(port), service);
connConfig.setSASLAuthenticationEnabled(false);
try {
connection = new XMPPConnection(connConfig);
connection.connect();
Log.i("XMPPClient",
"[SettingsDialog] Connected to " + connection.getHost());
} catch (XMPPException ex) {
Log.e("XMPPClient", "[SettingsDialog] Failed to connect to "
+ connection.getHost());
Log.e("XMPPClient", ex.toString());
}
//Login to the server
try {
connection.login(username, password, "Smack" + new Date().getTime());
Log.i("XMPPClient", "Logged in as " + connection.getUser());
Presence presence = new Presence(Presence.Type.available);// Set the presence to available
connection.sendPacket(presence);
} catch (XMPPException ex) {
Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username);
Log.e("XMPPClient", ex.toString());
return null;
}
//initialize();
initialize();//Add packet listener on connection for listen any message received
return connection;
}
此连接对象将帮助您找到您的用户是否已连接