SMACK:我如何监听用户可用性状态的变化?

时间:2012-10-25 11:29:43

标签: smack asmack

如何在SMACK中订阅收听用户可用性状态更改?

要获取用户的可用性状态,请使用以下命令:

XMPPConnection.getRoster().getPresence(name).isAvailable();

但我如何订阅,以便在状态发生变化时收到一些通知? (所以我没有投票)。

3 个答案:

答案 0 :(得分:6)

答案 1 :(得分:4)

此代码可以帮助您:

roster.addRosterListener(new RosterListener() {
                // Ignored events public void entriesAdded(Collection<String> addresses) {}
                public void entriesDeleted(Collection<String> addresses) {}
                public void entriesUpdated(Collection<String> addresses) {}
                public void presenceChanged(Presence presence) {
                    System.out.println("Presence changed: " + presence.getFrom() + " " + presence);
                }
                @Override
                public void entriesAdded(Collection<String> arg0) {
                    // TODO Auto-generated method stub

                }
            });

答案 2 :(得分:2)

roster.addRosterListener(new RosterListener() {
            // Ignored events public void entriesAdded(Collection<String> addresses) {}
            public void entriesDeleted(Collection<String> addresses) {}
            public void entriesUpdated(Collection<String> addresses) {}
            public void presenceChanged(Presence presence) {

                Log.e(TAG, presence.getStatus());
                    Log.e(TAG,presence.getFrom());
                    Log.e(TAG, presence.getLanguage());
                    Log.e(TAG,presence.getDefaultLanguage());
                    Log.e(TAG, presence.getType().toString());
            }
            @Override
            public void entriesAdded(Collection<String> arg0) {
                // TODO Auto-generated method stub

            }
        });