ConnectionConfiguration cc = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(cc);
try
{
// Connect
connection.connect();
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
// Login with appropriate credentials
connection.login("***@gmail.com", "***");
ChatManager chatMgr = connection.getChatManager();
Chat chat = chatMgr.createChat("***@gmail.com", null);
chat.sendMessage("hello");
// Get the user's roster
Roster roster = connection.getRoster();
// Print the number of contacts
//System.out.println("Number of contacts: " + roster.getEntryCount());
Log.i("whf", "Number of contacts: " + roster.getEntryCount());
// Enumerate all contacts in the user's roster
for (RosterEntry entry : roster.getEntries())
{
Log.i("whf", "Number of contacts: " + roster.getEntryCount());
}
}
catch (XMPPException e)
{
// Do something better than this!
e.printStackTrace();
}
finally
{
connection.disconnect();
}
Android 基于XMPP协议连接GTalk
最新推荐文章于 2024-10-13 12:12:26 发布