how ot get lastactivity using openfire server and asmack in android

720 views Asked by At
LastActivity lastActivity = new LastActivity();
lastActivity.setTo(mpresence_array.get(i)+"@ip-108-62-33-145.secureserver.net/Smack");

long seconds = lastActivity.lastActivity; 
Log.d(Tag,"Last Seen by : "+seconds);

But it will return -1 only

I am aslo tried this one

but I am getting exception like this

I used Smack library and I tried to get the lastactivty like below.

LastActivty lastSeen = LastActivityManager.getLastActivity(
           ConnectionManager.getInstance().getXmppConn ection(),
           Utils.createXmppUserIdByUserId(friendId));

But it gave me the follwing error

08-05 11:59:36.299: E/AndroidRuntime(14006): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.zobichat.activity/com.MyChat.activity.ChatInitialActivity}: java.lang.ClassCastException: org.jivesoftware.smack.util.PacketParserUtils$2 cannot be cast to org.jivesoftware.smackx.packet.LastActivity

How can I fix this? Please help.

1

There are 1 answers

0
Kaushik Makwana On

try this

LastActivityManager lastactivity = LastActivityManager.getInstanceFor(MyXMPPconnection);
LastActivity k = lastactivity.getLastActivity(JID); // user jid
Log.d("Last seen",k.lastActivity");