本文整理匯總了Java中org.jivesoftware.smack.XMPPConnection.sendPacket方法的典型用法代碼示例。如果您正苦於以下問題:Java XMPPConnection.sendPacket方法的具體用法?Java XMPPConnection.sendPacket怎麽用?Java XMPPConnection.sendPacket使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.XMPPConnection
的用法示例。
在下文中一共展示了XMPPConnection.sendPacket方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setPresence
import org.jivesoftware.smack.XMPPConnection; //導入方法依賴的package包/類
/**
* 設置用戶狀態
* @param xmppConnection
* @param type 狀態
* @param status 狀態描述
* @return
*/
public static boolean setPresence(XMPPConnection xmppConnection,Presence.Type type,String status){
Presence presence=new Presence(type);
presence.setStatus(status);
try{
xmppConnection.sendPacket(presence);
return true;
}catch (Exception e){
return false;
}
}
示例2: addUserHaveGroup
import org.jivesoftware.smack.XMPPConnection; //導入方法依賴的package包/類
/**
* 添加好友 有分組
* @param xmppConnection
* @param userName 用戶名
* @param name 備注名
* @param groupName 分組名
* @return
*/
public static boolean addUserHaveGroup(XMPPConnection xmppConnection,String userName, String name, String groupName) {
try {
Presence subscription = new Presence(Presence.Type.subscribed);
subscription.setTo(userName);
userName += "@" + xmppConnection.getServiceName();
xmppConnection.sendPacket(subscription);
xmppConnection.getRoster().createEntry(userName, name, new String[] { groupName });
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例3: regist
import org.jivesoftware.smack.XMPPConnection; //導入方法依賴的package包/類
/**
* 注冊用戶
* @param xmppConnection
* @param userName
* @param password
* @return 1、注冊成功 0、服務器沒有返回結果2、這個賬號已經存在3、注冊失敗
*/
public static int regist(XMPPConnection xmppConnection, String userName, String password) {
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
registration.setTo(xmppConnection.getServiceName());
registration.setUsername(userName);
registration.setPassword(password);
// 這邊addAttribute不能為空,否則出錯。所以做個標誌是android手機創建的吧!!!!!
registration.addAttribute("android", "fhr");
PacketFilter filter = new AndFilter(new PacketIDFilter(registration.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = xmppConnection.createPacketCollector(filter);
xmppConnection.sendPacket(registration);
IQ result = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results停止請求results(是否成功的結果)
collector.cancel();
if (result == null) {
Log.e("regist", "No response from server.");
return 0;
} else if (result.getType() == IQ.Type.RESULT) {
Log.v("regist", "regist success.");
return 1;
} else {
if (result.getError().toString().equalsIgnoreCase("conflict(409)")) {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 2;
} else {
Log.e("regist", "IQ.Type.ERROR: " + result.getError().toString());
return 3;
}
}
}
示例4: setPresence
import org.jivesoftware.smack.XMPPConnection; //導入方法依賴的package包/類
/**
* 設置用戶狀態
* @param xmppConnection
* @param type
* @param status
* @return
*/
public static boolean setPresence(XMPPConnection xmppConnection, Presence.Type type, String status) {
Presence presence = new Presence(type);
presence.setStatus(status);
try {
xmppConnection.sendPacket(presence);
return true;
} catch (Exception e) {
Log.e("setPresence", e.getMessage());
return false;
}
}
示例5: addUserHaveGroup
import org.jivesoftware.smack.XMPPConnection; //導入方法依賴的package包/類
/**
* 添加好友 有分組
* @param xmppConnection
* @param userName 用戶名
* @param name 備注名
* @param groupName 分組名
* @return
*/
public static boolean addUserHaveGroup(XMPPConnection xmppConnection, String userName, String name, String groupName) {
try {
Presence subscription = new Presence(Presence.Type.subscribed);
subscription.setTo(userName);
userName += "@" + xmppConnection.getServiceName();
xmppConnection.sendPacket(subscription);
xmppConnection.getRoster().createEntry(userName, name, new String[]{groupName});
return true;
} catch (Exception e) {
Log.e("addUser", e.getMessage());
e.printStackTrace();
return false;
}
}
示例6: changeStateMessage
import org.jivesoftware.smack.XMPPConnection; //導入方法依賴的package包/類
/**
* 修改心情
* @param xmppConnection
* @param status
*/
public static void changeStateMessage(XMPPConnection xmppConnection,String status) {
Presence presence = new Presence(Presence.Type.available);
presence.setStatus(status);
xmppConnection.sendPacket(presence);
}
示例7: changeStateMessage
import org.jivesoftware.smack.XMPPConnection; //導入方法依賴的package包/類
/**
* 修改心情
*
* @param xmppConnection
* @param status
*/
public static void changeStateMessage(XMPPConnection xmppConnection, String status) {
Presence presence = new Presence(Presence.Type.available);
presence.setStatus(status);
xmppConnection.sendPacket(presence);
}