5

私のGmailステータスでカウントダウンを公開することは可能ですか? 「01:44:15:23」のように、継続的に減少します。

4

2 に答える 2

4

Found a good article to share:

Google Talk uses XMPP then if you can connect using an XMPP client to your Google account you can use the client instead of Google talk.

The whole mechanism is too simple (Used the Smack XMPP Library because it is simple and serves me well):

  1. Login.
  2. Calculate difference between now and the targeted date.
  3. Send the presence

Login

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.
}

Calculate difference between now and the targeted date

This process is done using Java Calendar and Date objects:

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);
}

This code calculates the difference between the two dates in days, hours and minutes.

Send the presence

After calculating the difference all we have to do is to send the presence:

import org.jivesoftware.smack.packet.Presence;

{
         String remaining = Long.toString(diffDays) + " day(s), " + Long.toString(diffHours) + " hour(s), " + Long.toString(diffMinutes) + " minute(s) " + message; //Message is usually: Until "something".

        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);
}

After this point people will see your new status instead of the one in Google Talk. (Notice that you won’t be able to see the change inside Google Talk but rest assured it is changed.f you wanna make sure it is changed ask one of your friends to tell you your status).

于 2013-02-24T10:55:13.747 に答える
2

ここ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 分ごとに更新されます。詳細については、こちらをご覧ください

于 2013-02-26T06:17:33.830 に答える