Home > DeveloperSection > Forums > Getting timestamp from incoming xmpp message
Glen Martin
Glen Martin

Total Post:27

Posted on    June-16-2015 11:53 PM

 Android Android 

 1 Reply(s)
 3720  View(s)
Rate this:

I am using aSmack library to communicate with remote xmpp server. I am able to send/receive messages, but I want to get timestamp of incoming message.

Could you tell me please, is it possible at all? 

Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    June-17-2015 6:59 AM

Timestamp is not part of the regular messages. Therefore you cannot extract it.

There is a spec (as mentioned by @Dmitry), but this only applies to specific types of messages. Typically those that are NOT realtime, such as offline and publishing the last pubsub message of a node when a new subscription is created. These are messages with an inherent delay built into the

Due to specs time is required attribute for XMPP message:

Check the <delay> item of <message>:

<delay xmlns='urn:xmpp:delay'
Offline Storage
But getting it looks a bit tricky. As soon as aSmack is recompiled Smack with some replaced stuff, so try to get it the way like here:

DelayInformation inf = null;
try {
    inf = (DelayInformation)packet.getExtension("x","jabber:x:delay");
} catch (Exception e) {
// get offline message timestamp
    Date date = inf.getStamp();

Problably, you will need to check what server sends with message as extension value and replace "jabber:x:delay" with 'urn:xmpp:delay' as it is shown in XMPP specs example.

But not sure if it works.

Don't want to miss updates? Please click the below button!

Follow MindStick