Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

smack RosterListener not working in Android

Currently I am Working chat applicaiton using Xmpp SMACK API.but when i have called addrosterListener then i am not getting Presence current status.I have to reference of http://www.igniterealtime.org/builds/smack/docs/3.2.2/javadoc/org/jivesoftware/smack/RosterListener.html .please help me.

roster.addRosterListener(new RosterListener() {
                        @Override
                        public void presenceChanged(Presence presence) {


                            Log.d("pewsence ", "pewsence Status: " + presence.getFrom());
                            Log.d("pewsence ", "pewsence to Status: "
                                    + presence.getTo() + " " + presence);

                            // Called when the presence of a roster entry is
                            // changed
                        }

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

                        }

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

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

this listener is call when activity created.I think refer to the all documents,this listener is called automatically when presense will change.

Thanks in advance.

like image 580
dipali Avatar asked Nov 12 '22 00:11

dipali


1 Answers

roster = connection.getRoster();

            // Get all rosters
            Log.i("roster", "roster=" + connection.isConnected() + "-" + roster);
            Collection<RosterEntry> entries = roster.getEntries();
            // loop through
            for (RosterEntry entry : entries) {
                Presence entryPresence = roster.getPresence(entry.getUser());
                Presence.Type userType = entryPresence.getType();

            }

Using this code ,you have to get all online or offline users.and u can chat with anyone.

like image 143
dipali Avatar answered Nov 14 '22 22:11

dipali