Please is it possible to publish a countdown in my gmail status? Like "01:44:15:23" and its decrements continually.
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):
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).
Its very simple just download status-counter.jar
from here and write a script file
java -jar /root/status-counter.jar -status SF -username [email protected] -password XXXXXX -datetime 2013-03-21T16:00:00+02:00 -type hours -decimals 0
and write a cron to do the job
*/5 * * * * /path/script.sh > /dev/null
this updates your status every 5 minutes. More details can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With