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

时光怂恿深爱的人放手 提交于 2020-01-25 14:33:09

问题


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());

             }
         }
        });

回答1:


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:

Hope it will solve your problem.



来源:https://stackoverflow.com/questions/27598454/check-online-offline-user-of-openfire-and-auto-accept-friend-request-using-andro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!