I am using asmack 4.0.5 and want to retreive last seen of a users. I tried using:
LastActivityManager lActivityManager = LastActivityManager.getInstanceFor(mConnection);
try {
Log.v(TAG,"Last Activity: " + ActivityManager.getLastActivity(pArg0.getFrom()));
} catch (NoResponseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XMPPErrorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
But this always returns 0 seconds.It should be like when app is in background then user should be shown as offline.The user is only online when he has app in foreground .Does anybody has any idea how to get last seen of user.
One should send a packet with status "Online" when it comes online and "Offline" when it goes offline (when app goes in background, send 'Offline'). Only now server will be able to let other people know when they asks.
Now when A wants to know the last seen status for B and server returns 0, then according to documentation, it means, B is online already.. :) otherwise it will be elapsed time. Read here for more details.
LastActivityManager Source Docs
Official XEP-0012