創建全局XMPPConnection對象並使用下面的funciton並存儲在全局XMPPConnection對象中,並在任何地方使用該連接對象。這是一個示例gtalk示例。
public XMPPConnection login() throws XMPPException {
ConnectionConfiguration config = new
ConnectionConfiguration("talk.google.com",5222,"gmail.com");
config.setSecurityMode(SecurityMode.required);
config.setTruststoreType("BKS");
config.setTruststorePath("/system/etc/security/cacerts.bks");
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login(username, password);
Presence presence = new Presence(Presence.Type.available);
presence.setMode(Presence.Mode.available);
connection.sendPacket(presence);
try {
Thread.sleep(3000);
} catch (Exception ex) {
ex.printStackTrace();
}
return connection;
}
可以ü請參閱我的問題中,我有我寫的連接code.So第一個鏈接我如何可以使用任何其他活動嗎?或者您能不能給一些代碼,獲得清晰的概念。 – Nency 2012-07-05 11:23:32
存在狀態=新狀態(Presence.Type.available); connection.sendPacket(presence); xmppClient.setConnection(connection);在這段代碼中,setconnection sunction僅在XMPPClient.java文件中,所以我如何在不同的活動中使用此代碼。 – Nency 2012-07-05 11:25:39
先告訴我你想要什麼。請解釋清楚。 – 2012-07-05 11:32:18