本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.setFrom方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.setFrom方法的具體用法?Java Presence.setFrom怎麽用?Java Presence.setFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.packet.Presence
的用法示例。
在下文中一共展示了Presence.setFrom方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: enableUser
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* This method sends a friend request to the user if he isn't already in the bots {@link Roster}
* . {@inheritDoc}
*/
@Override
public void enableUser(String username) {
if (!connection.isConnected()) {
return;
}
Roster roster = connection.getRoster();
if (roster != null && roster.getEntry(username) != null) {
return;
}
try {
String clientId = ClientAndChannelContextHolder.getClient().getClientId();
Presence subscribe = new Presence(Presence.Type.subscribe);
subscribe.setFrom(sender);
subscribe.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix());
connection.sendPacket(subscribe);
Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setFrom(sender);
subscribed.setTo(username + "." + clientId + XMPPPatternUtils.getUserSuffix());
connection.sendPacket(subscribed);
} catch (NotConnectedException e) {
LOG.debug("Could not send friendship request because XMPP connector is disconnected");
}
}
示例2: getAllPresences
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* Returns a List of Presence objects for all of a user's current presences if no presence information is available,
* such as when you are not subscribed to the user's presence updates.
*
* @param bareJid an XMPP ID, e.g. [email protected]
* @return a List of Presence objects for all the user's current presences, or an unavailable presence if no
* presence information is available.
*/
public List<Presence> getAllPresences(String bareJid) {
Map<String, Presence> userPresences = presenceMap.get(getMapKey(bareJid));
List<Presence> res;
if (userPresences == null) {
// Create an unavailable presence if none was found
Presence unavailable = new Presence(Presence.Type.unavailable);
unavailable.setFrom(bareJid);
res = new ArrayList<>(Arrays.asList(unavailable));
} else {
res = new ArrayList<>(userPresences.values().size());
for (Presence presence : userPresences.values()) {
res.add(presence.clone());
}
}
return res;
}
示例3: login
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void login(String user, String pass, StatusItem status, String username)
throws XMPPException, SmackException, IOException, InterruptedException {
Log.i(TAG, "inside XMPP getlogin Method");
long l = System.currentTimeMillis();
XMPPTCPConnection connect = connect();
if (connect.isAuthenticated()) {
Log.i(TAG, "User already logged in");
return;
}
Log.i(TAG, "Time taken to connect: " + (System.currentTimeMillis() - l));
l = System.currentTimeMillis();
connect.login(user, pass);
Log.i(TAG, "Time taken to login: " + (System.currentTimeMillis() - l));
Log.i(TAG, "login step passed");
Presence p = new Presence(Presence.Type.available);
p.setMode(Presence.Mode.available);
p.setPriority(24);
p.setFrom(connect.getUser());
if (status != null) {
p.setStatus(status.toJSON());
} else {
p.setStatus(new StatusItem().toJSON());
}
// p.setTo("");
VCard ownVCard = new VCard();
ownVCard.load(connect);
ownVCard.setNickName(username);
ownVCard.save(connect);
PingManager pingManager = PingManager.getInstanceFor(connect);
pingManager.setPingInterval(150000);
connect.sendPacket(p);
}
示例4: sendSubscriptionRequest
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* This method sends a subscription request to the sender.
*
* @param presence
* The presence used for sender and receiver information.
* @throws NotConnectedException
*/
private void sendSubscriptionRequest(Presence presence) throws NotConnectedException {
int priority = CommunoteRuntime.getInstance().getConfigurationManager()
.getApplicationConfigurationProperties()
.getProperty(ApplicationPropertyXmpp.PRIORITY, 100);
Presence subscription = new Presence(Presence.Type.subscribe);
subscription.setPriority(priority);
subscription.setFrom(presence.getTo());
subscription.setTo(presence.getFrom());
presence.setType(Presence.Type.subscribed);
presence.setFrom(subscription.getFrom());
presence.setTo(subscription.getTo());
connection.sendPacket(presence);
connection.sendPacket(subscription);
}
示例5: login
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* This method lets you send the presence direct to the gateway. Type, To and From
* are modified.
* @param presence the presence used to login to gateway
*/
public void login(Presence presence){
presence.setType(Presence.Type.available);
presence.setTo(entityJID);
presence.setFrom(connection.getUser());
connection.sendPacket(presence);
}
示例6: logout
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* This method logs you out from this gateway by sending an unavailable presence
* to directly to this gateway.
*/
public void logout(){
Presence presence = new Presence(Presence.Type.unavailable);
presence.setTo(entityJID);
presence.setFrom(connection.getUser());
connection.sendPacket(presence);
}
示例7: processPacket
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void processPacket(Packet packet) {
if(packet instanceof Presence){
Presence presence = (Presence)packet;
if(entityJID.equals(presence.getFrom()) &&
roster.contains(presence.getFrom()) &&
presence.getType().equals(Presence.Type.subscribe)){
Presence response = new Presence(Presence.Type.subscribed);
response.setTo(presence.getFrom());
response.setFrom(StringUtils.parseBareAddress(connection.getUser()));
connection.sendPacket(response);
}
}
}
示例8: broadcastMyPresence
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* A special method to broadcast our own presence.
*/
private void broadcastMyPresence(String id) {
Presence presence = createPresence(null);
presence.setFrom(mConnection.getUser());
Intent i = PresenceListener.createIntent(this, presence, null);
i.putExtra(EXTRA_FINGERPRINT, getMyFingerprint());
i.putExtra(EXTRA_SUBSCRIBED_FROM, true);
i.putExtra(EXTRA_SUBSCRIBED_TO, true);
// to keep track of request-reply
i.putExtra(EXTRA_PACKET_ID, id);
mLocalBroadcastManager.sendBroadcast(i);
}
示例9: logout
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* This method logs you out from this gateway by sending an unavailable
* presence to directly to this gateway.
*/
public void logout() {
Presence presence = new Presence(Presence.Type.unavailable);
presence.setTo(entityJID);
presence.setFrom(connection.getUser());
connection.sendPacket(presence);
}
示例10: processPacket
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
public void processPacket(Packet packet) {
if (packet instanceof Presence) {
Presence presence = (Presence) packet;
if (entityJID.equals(presence.getFrom())
&& roster.contains(presence.getFrom())
&& presence.getType().equals(Presence.Type.subscribe)) {
Presence response = new Presence(Presence.Type.subscribed);
response.setTo(presence.getFrom());
response.setFrom(StringUtils.parseBareAddress(connection
.getUser()));
connection.sendPacket(response);
}
}
}
示例11: login
import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
* This method lets you send the presence direct to the gateway. Type, To
* and From are modified.
*
* @param presence
* the presence used to login to gateway
*/
public void login(Presence presence) {
presence.setType(Presence.Type.available);
presence.setTo(entityJID);
presence.setFrom(connection.getUser());
connection.sendPacket(presence);
}