本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.isAvailable方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.isAvailable方法的具體用法?Java Presence.isAvailable怎麽用?Java Presence.isAvailable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.packet.Presence
的用法示例。
在下文中一共展示了Presence.isAvailable方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getFullThingJidOrNotify
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
EntityFullJid getFullThingJidOrNotify() {
EntityBareJid thingJid = settings.getThingJid();
IoTProvisioningManager ioTProvisioningManager = IoTProvisioningManager.getInstanceFor(xmppConnection);
if (!ioTProvisioningManager.iAmFriendOf(thingJid)) {
withMainActivity((ma) -> Toast.makeText(ma, "Can not perform action. Not befriended with thing", Toast.LENGTH_LONG).show());
return null;
}
Presence presence = roster.getPresence(settings.getThingJid());
if (presence == null || !presence.isAvailable()) {
withMainActivity((ma) -> Toast.makeText(ma, "Can not perform action. Befriended with thing, but thing is not online/unavailable", Toast.LENGTH_LONG).show());
return null;
}
EntityFullJid fullOtherJid = presence.getFrom().asEntityFullJidIfPossible();
if (fullOtherJid == null) throw new IllegalStateException("Exepected full JID");
return fullOtherJid;
}
示例2: isAvailable
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*
* @param username
* Has to be in the messagers format.
*/
@Override
public boolean isAvailable(String username) {
if (connection.isConnected()) {
Roster roster = connection.getRoster();
if (roster != null) {
Presence presence = roster.getPresence(username + XMPPPatternUtils.getUserSuffix());
return presence.isAvailable();
} else {
LOG.debug("XMPP connection did not return a roster for communote bot");
}
} else {
LOG.debug("Cannot check availability of user because XMPP connector is disconnected");
}
return false;
}
示例3: presenceChanged
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@Override
public void presenceChanged(Presence presence)
{
log.fine("Presence change from " + presence.getFrom());
String name = StringUtils.parseName(presence.getFrom());
if (!isMultiplicityDevice(name))
{
return;
}
if (presence.isAvailable())
{
notifyDeviceAvailable(name);
}
else
{
notifyDeviceUnavailable(name);
}
}
示例4: notifyCurrentPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Notify current presence.
*
* @param connection
* the connection
*/
private void notifyCurrentPresence(XMPPConnection connection)
{
if (multiplicityGroup == null)
{
log.log(Level.WARNING, "Could not find the multiplicity roster group.");
return;
}
log.log(Level.FINE, "Loading roster entries.");
for (RosterEntry re : multiplicityGroup.getEntries())
{
log.finer("Roster entry check availability on " + re.getUser());
Presence presence = roster.getPresence(re.getUser());
if (presence.isAvailable())
{
log.finer(" is available!");
notifyDeviceAvailable(re.getName());
}
}
}
示例5: searchServices
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private static MappedNodes searchServices(final ConcurrentHashMap<String, String> visited, final XMPPConnection xmppConnection, final int maxEntries, final int maxDepth, final int maxSearchNodes, final String protocol, final boolean searchBuddies, final MappedNodes mappedNodes) {
if (xmppConnection == null || !xmppConnection.isConnected()) {
return null;
}
searchDiscoItems(xmppConnection, maxEntries, xmppConnection.getServiceName(), mappedNodes, maxDepth - 1, maxSearchNodes, protocol, visited);
// Request to Server
deepSearch(xmppConnection, maxEntries, xmppConnection.getHost(), mappedNodes, maxDepth - 1, maxSearchNodes, protocol, visited);
// Request to Buddies
if (xmppConnection.getRoster() != null && searchBuddies) {
for (final RosterEntry re : xmppConnection.getRoster().getEntries()) {
for (final Iterator<Presence> i = xmppConnection.getRoster().getPresences(re.getUser()); i.hasNext();) {
final Presence presence = i.next();
if (presence.isAvailable()) {
deepSearch(xmppConnection, maxEntries, presence.getFrom(), mappedNodes, maxDepth - 1, maxSearchNodes, protocol, visited);
}
}
}
}
return mappedNodes;
}
示例6: setJidPresenceGui
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private void setJidPresenceGui(ImageView imageView, BareJid bareJid) {
if (bareJid == null) return;
Presence presence = roster.getPresence(bareJid);
final Drawable drawable;
if (presence != null && presence.isAvailable()) {
drawable = mOnlineDrawable;
} else {
drawable = mOfflineDrawable;
}
imageView.setImageDrawable(drawable);
}
示例7: isRecipientOnline
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Check if given recipient is whether online or not.
*
* @param jid
* @return true iff the provided JID is not null or empty and it is online.
*/
public boolean isRecipientOnline(String jid) {
boolean isOnline = false;
if (jid != null && !jid.isEmpty()) {
String jidFinal = getFullJid(jid);
Presence presence = Roster.getInstanceFor(connection).getPresence(jidFinal);
if (presence != null) {
isOnline = presence.isAvailable();
}
}
return isOnline;
}
示例8: getAvailablePresences
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Returns a List of all <b>available</b> Presence Objects for the given bare JID. If there are no available
* presences, then the empty list will be returned.
*
* @param bareJid the bare JID from which the presences should be retrieved.
* @return available presences for the bare JID.
*/
public List<Presence> getAvailablePresences(String bareJid) {
List<Presence> allPresences = getAllPresences(bareJid);
List<Presence> res = new ArrayList<>(allPresences.size());
for (Presence presence : allPresences) {
if (presence.isAvailable()) {
// No need to clone presence here, getAllPresences already returns clones
res.add(presence);
}
}
return res;
}
示例9: getDeviceNamesOnline
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Gets the device names online.
*
* @param deviceType
* the device type
* @return the device names online
*/
public List<String> getDeviceNamesOnline(String deviceType)
{
List<String> list = new ArrayList<String>();
if (connection == null)
{
return list;
}
Roster roster = connection.getRoster();
if (roster == null)
{
return list;
}
try
{
RosterGroup rg = roster.getGroup(deviceType);
for (RosterEntry re : rg.getEntries())
{
Presence p = connection.getRoster().getPresence(re.getUser());
if (p.isAvailable())
{
list.add(re.getName());
}
}
}
catch (NullPointerException e)
{
}
return list;
}
示例10: presenceChanged
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Listennig for a change in presence of the user, eg: unavailable => available
*
* @param presence
*/
@Override
public void presenceChanged(Presence presence) {
String user = presence.getFrom();
if (user.contains(xmppUserId) && presence.isAvailable()) {
isOnline = true;
}
}
示例11: fetchRosterEntries
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/** fetchRosterEntries
*
*/
private void fetchRosterEntries() {
Collection<RosterEntry> rosterEntries = roster.getEntries();
for (RosterEntry entry : rosterEntries) {
Presence presence = roster.getPresence(entry.getUser());
Contact contact;
contact = new Contact(entry.getUser(), presence.isAvailable());
eventbus.contactEvent(contact);
}
}
示例12: authenticate
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Authenticating a particular user
*
* @return true if authentication is successful, and false otherwise.
*/
public boolean authenticate() {
//creating the connection
XMPPConnection connection = createConnection();
//connecting to the server
boolean connectionStatus = connect(connection);
if (!connectionStatus) {
log.info("Failed to connect to the Server");
return false;
}
//signing in
boolean loginStatus = login(connection);
if (!loginStatus) {
log.info("login failed");
return false;
}
Roster roster = connection.getRoster();
Presence presence = roster.getPresence(userXmppId);
boolean isAvailable = false;
if (!presence.isAvailable()) {
isAvailable = checkforUserAvailability(roster, userXmppId);
}
if (!isAvailable) {
log.info("user is not online");
return false;
}
boolean validation = getUserResponse(connection, userXmppId);
// Giving a second chance to provide the PIN
if (!validation && !pinDisabledResponse) {
validation = getUserResponse(connection, userXmppId);
}
return validation;
}
示例13: checkforUserAvailability
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Checking whether the user is available in the contact list.
*
* @param roster
* @param userXmppId
* @return
*/
public boolean checkforUserAvailability(Roster roster, String userXmppId) {
boolean isAvailable = false;
XmppSubscriptionListener listener = new XmppSubscriptionListener(userXmppId);
roster.addRosterListener(listener);
Presence presence = roster.getPresence(userXmppId);
boolean status = isAvailable(roster, userXmppId);
try {
if (!status) {
if (log.isInfoEnabled()) {
log.info("The User is not subscribed.");
}
boolean contactAddStatus = new XmppSubscriber().addContact(roster, userXmppId);
if (contactAddStatus) {
if (log.isInfoEnabled()) {
log.info("User's Contact is added successfully..");
}
} else {
if (log.isInfoEnabled()) {
log.info("Failed to add contact.");
}
}
if (!presence.isAvailable()) {
while (!listener.isOnline()) {
Thread.sleep(5000);
}
}
isAvailable = true;
} else {
if (log.isInfoEnabled()) {
log.info("User is not online..");
}
while (!listener.isOnline()) {
Thread.sleep(5000);
}
isAvailable = true;
}
} catch (InterruptedException e) {
log.error("Error while checking user availability", e);
} finally {
roster.removeRosterListener(listener);
}
return isAvailable;
}
示例14: getUserResponse
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Read the PIN number sent by the user as the reply.
*
* @param connection
* @param userName
* @return
*/
public boolean getUserResponse(XMPPConnection connection, String userName) {
String response = null;
Presence presence = connection.getRoster().getPresence(userName);
if (presence.isAvailable()) {
try {
ChatManager chatManager = connection.getChatManager();
Chat chat = chatManager.createChat(userName, null);
PacketFilter filter =
new AndFilter(new PacketTypeFilter(Message.class), new FromContainsFilter(userName));
XmppResponseListener chatListener = new XmppResponseListener();
connection.addPacketListener(chatListener, filter);
if (isPINEnabled) {
chat.sendMessage("Please reply with your PIN Number here.");
if (log.isInfoEnabled()) {
log.info("User PIN is sent to the user and awaiting for the response.");
}
while (!chatListener.isResponseReceived()) {
Thread.sleep(100);
}
response = chatListener.getResponse();
if (response != null) {
return userPIN.contentEquals(response.trim());
}
} else {
chat.sendMessage(
"You are about to get authenticated for your OpenID. Do you want to continue: [Yes] or [No]");
if (log.isInfoEnabled()) {
log.info("User PIN is sent to the user and awaiting for the response.");
}
while (!chatListener.isResponseReceived()) {
Thread.sleep(100);
}
response = chatListener.getResponse();
if (response != null) {
if ("YES".equalsIgnoreCase(response.trim())) {
return true;
} else if ("NO".equalsIgnoreCase(response.trim())) {
return false;
} else {
pinDisabledResponse = false;
return false;
}
}
}
} catch (Exception e) {
log.error("Error while getting user response", e);
}
} else {
return false;
}
return false;
}