androidopenfirerostering

Check Online/Offline User of Openfire and auto accept friend request Using Android


I am using openfire server in android. Now I need to check how many users are online and who are they. My connection is OK. But when I check it the output is Look Like,


Called when the presence of a roster entry is changed

Name: esty

Status: unavailable

Called when the presence of a roster entry is changed

Name: roni

Status: unavailable


So How to check who are online or offline. Another question is how to automatic accept the request. Please I need help.

Here Is My code:

public void OnlineUser()
{

    final Roster sroster = connection.getRoster();

    try {
        sroster.createEntry("esty", "roni", null);
    } catch (XMPPException e) {

        e.printStackTrace();
    }


     Presence presence = new Presence(Presence.Type.available);
     connection.sendPacket(presence);
 //  context.setConnection(Constants.connection);

    // final Roster roster =connection.getRoster();
     final Collection<RosterEntry> entries = sroster.getEntries();

    sroster.addRosterListener(new RosterListener() {
         @Override
         public void presenceChanged(Presence presence) {
           //Called when the presence of a roster entry is changed
             for (RosterEntry entry : entries) {



                    Log.v("roni", "Called when the presence of a roster entry is changed ");
                         Presence entryPresence = sroster.getPresence(entry.getUser());

                         Presence.Type type = entryPresence.getType();       
                         uName =entry.getName().toString();
                         uStatus=type.toString();
                         Log.v("roni", "Name: " + entry.getName().toString());
                         Log.v("roni", "Status: " +type.toString());

                 }
         }
         @Override
         public void entriesUpdated(Collection<String> arg0) {
           // Called when a roster entries are updated.
             for (RosterEntry entry : entries) {


                    Log.v("roni", "Called when a roster entries are updated ");
                         Presence entryPresence = sroster.getPresence(entry.getUser());

                         Presence.Type type = entryPresence.getType();       
                         uName =entry.getName().toString();
                         uStatus=type.toString();
                         Log.v("roni", "Namne: " + entry.getName().toString());
                         Log.v("roni", "Status: " +type.toString());

                 }
         }
         @Override
         public void entriesDeleted(Collection<String> arg0) {
           // Called when a roster entries are removed.
             for (RosterEntry entry : entries) {


                    Log.v("roni", "Called when a roster entries are removed. ");
                         Presence entryPresence = sroster.getPresence(entry.getUser());

                         Presence.Type type = entryPresence.getType();       
                         uName =entry.getName().toString();
                         uStatus=type.toString();
                         Log.v("roni", "Namne: " + entry.getName().toString());
                         Log.v("roni", "Status: " +type.toString());

                 }
         }
        @Override
         public void entriesAdded(Collection<String> arg0) {
           // Called when a roster entries are added.
            for (RosterEntry entry : entries) {


                Log.v("roni", " Called when a roster entries are added. ");
                     Presence entryPresence = sroster.getPresence(entry.getUser());

                     Presence.Type type = entryPresence.getType();       
                     uName =entry.getName().toString();
                     uStatus=type.toString();
                     Log.v("roni", "Namne: " + entry.getName().toString());
                     Log.v("roni", "Status: " +type.toString());

             }
         }
        });

Solution

  • Are you using it with LDAP? If so, you can go into Users/Groups and then select a group. If you enable Contact list group sharing it should do the trick.

    "Enable contact list group sharing". See my screenshot for details: enter image description here

    Hope it will solve your problem.