本文整理汇总了Java中org.jivesoftware.smack.roster.Roster.getPresence方法的典型用法代码示例。如果您正苦于以下问题:Java Roster.getPresence方法的具体用法?Java Roster.getPresence怎么用?Java Roster.getPresence使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jivesoftware.smack.roster.Roster
的用法示例。
在下文中一共展示了Roster.getPresence方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRosterEntryFor
import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
private XmppRosterEntry getRosterEntryFor(Roster roster, RosterEntry entry) {
XmppRosterEntry newEntry = new XmppRosterEntry();
newEntry.setXmppJID(entry.getUser())
.setAlias(entry.getName())
.setAvatar(getCachedAvatar(entry.getUser()));
if (newEntry.getAvatar() == null) {
newEntry.setAvatar(getAvatarFor(entry.getUser()));
}
Presence presence = roster.getPresence(entry.getUser());
newEntry.setAvailable(presence.isAvailable())
.setPresenceMode(presence.getMode().ordinal())
.setPersonalMessage(presence.getStatus());
newEntry.setUnreadMessages(mMessagesProvider.countUnreadMessages(mAccount.getXmppJid(), entry.getUser()));
return newEntry;
}
示例2: broadcastPresence
import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
private void broadcastPresence(Roster roster, RosterEntry entry, BareJid jid, String id) {
// this method might be called async
final LocalBroadcastManager lbm = mLocalBroadcastManager;
if (lbm == null)
return;
Intent i;
// entry present and not pending subscription
if (isRosterEntrySubscribed(entry) || Authenticator.isSelfJID(this, jid)) {
// roster entry found, look for presence
Presence presence = roster.getPresence(jid);
i = PresenceListener.createIntent(this, presence, entry);
}
else {
// null type indicates no roster entry found or not authorized
i = new Intent(ACTION_PRESENCE);
i.putExtra(EXTRA_FROM, jid.toString());
}
// to keep track of request-reply
i.putExtra(EXTRA_PACKET_ID, id);
lbm.sendBroadcast(i);
}
示例3: getInitialOnlineUsers
import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
/**
* Get online users from roster and store in onlineUsers
*/
private void getInitialOnlineUsers() {
Roster roster = Roster.getInstanceFor(connection);
Collection<RosterEntry> entries = roster.getEntries();
if (entries != null && !entries.isEmpty()) {
for (RosterEntry entry : entries) {
String jid = entry.getUser();
Presence presence = roster.getPresence(jid);
if (presence != null) {
XMPPError xmppError = presence.getError();
if (xmppError != null) {
logger.error(xmppError.getDescriptiveText());
} else {
try {
if (presence.getType() == Type.available) {
onlineUsers.add(jid.substring(0, jid.indexOf('@')));
} else if (presence.getType() == Type.unavailable) {
onlineUsers.remove(jid.substring(0, jid.indexOf('@')));
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
}
}
logger.debug("Online users: {}", onlineUsers.toString());
}
示例4: presenceChanged
import org.jivesoftware.smack.roster.Roster; //导入方法依赖的package包/类
@Override
public void presenceChanged(Presence presence) {
Roster roster = Roster.getInstanceFor(mConnection);
if (roster == null) {
Logger.info(TAG, "presenceChanged - No roster instance, skipping rebuild roster");
return;
}
ArrayList<XmppRosterEntry> entries = getRosterEntries();
if (entries == null || entries.isEmpty()) {
Logger.info(TAG, "presenceChanged - No roster entries. Skipping rebuild roster");
return;
}
String from = getXmppJid(presence.getFrom());
int index = entries.indexOf(new XmppRosterEntry().setXmppJID(from));
if (index < 0) {
Logger.info(TAG, "Presence from " + from + " which is not in the roster. Skipping rebuild roster");
return;
}
Presence rosterPresence = roster.getPresence(from);
entries.get(index)
.setAvailable(rosterPresence.isAvailable())
.setPresenceMode(rosterPresence.getMode().ordinal())
.setPersonalMessage(rosterPresence.getStatus());
Collections.sort(entries);
XmppServiceBroadcastEventEmitter.broadcastRosterChanged();
}