如何通过gmail状态发布倒计时?

时间:2012-06-07 15:42:11

标签: gmail status

请问我的gmail状态是否可以发布倒计时? 像“01:44:15:23”一样,它的不断减少。

2 个答案:

答案 0 :(得分:4)

找到一个好article to share

Google Talk使用XMPP,如果您可以使用XMPP clientGoogle account进行关联,则可以使用客户端而非Google Talk。

整个机制太简单了(使用Smack XMPP Library,因为它很简单并且很适合我):

  1. 登录。
  2. 计算现在和目标日期之间的差异。
  3. 发送状态
  4. <强>登录

    import org.jivesoftware.smack.XMPPConnection;
    
    public void connect() {
        XMPPConnection connection = new XMPPConnection(server); //Server is gmail.com for Google Talk.
        connection.connect();
        connection.login(username, password); //Username and password.
    }
    

    计算现在与目标日期之间的差异

    此过程使用Java Calendar和Date对象完成:

    import java.util.Calendar;
    import java.util.Date;
    
    {
            Calendar calendar1 = Calendar.getInstance();
            Date d = new Date();
            calendar1.setTime(d);
    
            Calendar calendar2 = Calendar.getInstance();
            calendar2.setTime(endLine); //End line is the date we're counting to.
    
            long milliseconds1 = calendar1.getTimeInMillis();
            long milliseconds2 = calendar2.getTimeInMillis();
            long diff = milliseconds2 - milliseconds1;
    
            long diffDays = diff / (24 * 60 * 60 * 1000);
            diff = diff % (24 * 60 * 60 * 1000);
    
            long diffHours = diff / (60 * 60 * 1000);
            diff = diff % (60 * 60 * 1000);
    
            long diffMinutes = diff / (60 * 1000);
            diff = diff % (60 * 1000);
    }
    

    此代码计算两个日期之间的差异,以天,小时和分钟为单位。

    发送状态

    在计算差异之后,我们所要做的就是发送存在:

    import org.jivesoftware.smack.packet.Presence;
    
    {
             String remaining = Long.toString(diffDays) + &quot; day(s), &quot; + Long.toString(diffHours) + &quot; hour(s), &quot; + Long.toString(diffMinutes) + &quot; minute(s) &quot; + message; //Message is usually: Until &quot;something&quot;.
    
            Presence presence = new Presence(Presence.Type.available);
            presence.setStatus(remaining);
            presence.setPriority(24); //Highest priority in Google Talk
            presence.setMode(presenceMode); //This is one of XMPP modes (Available, Chat, DND, Away, XA).
            connection.sendPacket(presence);
    }
    

    在此之后,人们会看到您的新状态,而不是Google Talk中的状态。 (请注意,您将无法看到Google Talk中的更改,但请放心更改。如果您想确保更改,请让您的朋友告诉您其状态。)

答案 1 :(得分:2)

非常简单,只需从here下载status-counter.jar并编写脚本文件

即可
java -jar /root/status-counter.jar -status SF -username username@gmail.com -password XXXXXX -datetime 2013-03-21T16:00:00+02:00 -type hours -decimals 0

并写一个cron来完成这项工作

*/5 * * * * /path/script.sh > /dev/null

每5分钟更新一次您的状态。可以找到更多详细信息here