5

目前我正在使用 Xmpp SMACK API 工作聊天应用程序。但是当我调用 addrosterListener 时,我没有获得当前状态。我必须参考 http://www.igniterealtime.org/builds/smack/docs/3.2.2 /javadoc/org/jivesoftware/smack/RosterListener.html .请帮帮我。

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.
                        }
                    });
                }
            }
        });

创建活动时调用此侦听器。我认为参考所有文档,当存在发生变化时会自动调用此侦听器。

提前致谢。

4

1 回答 1

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

            }

使用此代码,您必须获得所有在线或离线用户。您可以与任何人聊天。

于 2013-08-17T06:20:30.487 回答