-3

I am making a chatting application in android. I am able to perform the live chatting. But i am not able to get when the user is online or offline. How can I achieve the same

Thanks

here is the code

private void getListener() {
        Roster roster = connection.getRoster();
        Collection<RosterEntry> entries = roster.getEntries();
        for (RosterEntry rosterEntry : entries) {
            String user = rosterEntry.getUser();
            Presence presence = roster.getPresence(user);
            System.out.println("User : " + user);
            System.out.println("Presence : " + presence); // 1
            System.out.println("Presence type: " + presence.getType()); // 2
            System.out.println("Presence mode: " + presence.getMode());
        }
    }

but i always get the status unavailable, also when the person is available. Please tell me any solution what to do?? Thanks

Gaurav Arora
  • 8,282
  • 21
  • 88
  • 143
  • How can anyone answer your question without knowing a thing about your implementation? – Egor Oct 09 '12 at 07:59
  • Post code of the class, question is very vague. – Hassan Jawed Oct 09 '12 at 07:59
  • sory trickster. I am posting code rite now. – Gaurav Arora Oct 09 '12 at 08:29
  • @Trickster please help me now. I have posted the code – Gaurav Arora Oct 09 '12 at 09:14
  • @Trickster where are you now??? – Gaurav Arora Oct 09 '12 at 09:26
  • Is your project confidential one? Because, there is no line of code where you are setting the status of the user. Also, there are other users in the app as well, so you need to sync the status to server as well. There must be lot of code which I needed before I can through my answer. – Hassan Jawed Oct 09 '12 at 12:55
  • yar actually i have user asmack library and nothing else, and i have not written any code further for showing online and ofline. I just want to first print the status then i'l do further. Can u tell me how sync can be done. Server is showing the online and ofline status but i am always getting UNAVAILABLE in S.O.P Please help me @Trickster – Gaurav Arora Oct 10 '12 at 04:07

1 Answers1

0

Add an Online field to your users db, once logged it changed to true, once logged off changed it to false. In your chatting app, regularly (every 180 seconds) request your server for the user's Online field, and show that to the users.

Mohsen Afshin
  • 13,273
  • 10
  • 65
  • 90