Recognize the basic object-presence object in smack

Source: Internet
Author: User
Introduction to a presence object

Like IQ, presence is also a packet information packet that inherits from XMPP. presence mainly has two purposes: 1) Tell the current status of all clients on the server; 2) send a request to add/delete friends. Each presence information package has a type attribute presence. type, as follows:

  • Available: indicates that the instance is online.
  • Unavailable: indicates that the instance is offline.
  • Subscribe: sends out a friend adding Application
  • Unsubscribe: indicates an application to delete a friend.
  • Unsubscribed: deny adding peer to friend
  • Error: indicates that the presence message contains an error message.

In addition to the type information, presence also contains some optional attributes:

  • Status: custom text used to indicate the user's status, for example, going out for dinner
  • Priority: a non-negative number indicating the priority of the sender's resources (I have not yet figured out what the sender's resources are)
  • Mode: one of the five statuses: Online (default), chat, exit, XA (Extended away), do not disturb
Example 2

The following example shows a code segment that sends an invitation to join a friend's presence information package to the server:

Presence subscription = new Presence(Presence.Type.subscribe);subscription.setTo(packet.getFrom());ConnectionUtils.getConnection().sendPacket(subscription);
Three methods

Isavailable

public boolean isAvailable()

If the user is online, true is returned. Otherwise, false is returned. In addition, if the other user's presence information package contains an application for adding friends, false is returned. The Fai method is equivalent to GetType () = presence. type. Available. Note that when a user is online, the mode attribute value in the Presence information package may still be in the following modes (away),extended
away
Or Do Not Disturb (do
not disturb
).

Returned value: A boolean value in the online status.

Isaway

public boolean isAway()
Returns true if the presence type is
availableAnd
The presence mode is away, extended
away
, Or do
not disturb
. False will be returned when the type or mode is any other value, including when the presence type is unavailable (offline). This is a convenience method equivalent Type = type. Available &&
(Mode = mode. Away | mode = mode. Xa | mode = mode. DND).

Returns:
True if the presence type is available and the presence mode is away, XA, or DND.

 

GetType
public Presence.Type getType()
Returns the type of this presence packet.

Returns:
The type of the presence packet.

 

Settype
public void setType(Presence.Type type)
Sets the type of the presence packet.

Parameters:
type-The type of the presence packet.

 

Getstatus
public String getStatus()
Returns the status message of the presence update, or NullIf there is not a status. The status is free-form text describing a user's presence (I. e., "gone to lunch ").

Returns:
The status message.

 

Setstatus
public void setStatus(String status)
Sets the status message of the presence update. The status is free-form text describing a user's presence (I. e., "gone to lunch ").

Parameters:
status-The status message.

 

Getpriority
public int getPriority()
Returns the priority of the presence, or integer. min_value if no priority has been set.

Returns:
The priority.

 

Setpriority
public void setPriority(int priority)
Sets the priority of the presence. The valid range is-128 through 128.

Parameters:
priority-The priority of the presence.
Throws:
IllegalArgumentException
-If the priority is outside the valid range.

 

Getmode
public Presence.Mode getMode()
Returns the mode of the presence update, or
NullIf the mode is not set. A null presence mode value is interpreted to be the same thing Presence.Mode.available.

Returns:
The mode.

 

Setmode
public void setMode(Presence.Mode mode)
Sets the mode of the presence update. A null presence mode value is interpreted to be the same thing Presence.Mode.available.

Parameters:
mode-The mode.

 

Setlanguage
public void setLanguage(String language)
Sets the XML: Lang of this presence.

Parameters:
language-The XML: Lang of this presence.
Since:
3.0.2

 

Toxml
public String toXML()
Description copied from class:
Packet
Returns the packet as XML. every concrete extension of packet must implement this method. in addition to writing out packet-specific data, every sub-class shoshould also write out the error and the extensions data if they are defined.

Specified:
toXMLIn Class Packet
Returns:
The XML format of the packet as a string.

 

Tostring
public String toString()
Overrides:
toString
In Class Object

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.