gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 18:47:58 29 4
gpt4 key购买 nike

请问是否可以在我的 Gmail 状态中发布倒计时?
像“01:44:15:23”及其不断递减。

最佳答案

发现一个好 article to share :

Google Talk 使用 XMPP 那么如果您可以使用 XMPP client 连接给您的 Google account您可以使用客户端而不是 Google talk。

整个机制太简单了(使用了 Smack XMPP Library 因为它很简单而且对我很好):

  • 登录。
  • 计算现在和目标日期之间的差异。
  • 发送存在

  • 登录
    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) + " 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);
    }

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

    关于gmail - 如何通过 Gmail 状态发布倒计时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10935182/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com