获取gmail用户可用状态

时间:2010-09-04 05:25:19

标签: java

我有我的Gmail帐号的电子邮件列表...它使用了XMPP ...我怎样才能在java中获得这些用户状态可用性...

1 个答案:

答案 0 :(得分:2)

以下是使用Smack

的示例
SASLAuthentication.supportSASLMechanism("PLAIN");
ConnectionConfiguration config = new ConnectionConfiguration(
      "talk.google.com", 5222, "gmail.com");
XMPPConnection conn = new XMPPConnection(config);
conn.connect();
conn.login("yourid@gmail.com", "password");
Roster roster = conn.getRoster();
Collection<RosterEntry> set = roster.getEntries();
for (RosterEntry re: set) {
   System.out.println(">> " + re.getUser());            
   Presence pres = roster.getPresence(re.getUser());
   //This is the status. 
   System.out.println("\t> " + pres.getMode());
}

使用Prescence.getStatus()获取消息字符串