本文整理匯總了Java中org.jivesoftware.smack.XMPPConnection.createPacketCollector方法的典型用法代碼示例。如果您正苦於以下問題:Java XMPPConnection.createPacketCollector方法的具體用法?Java XMPPConnection.createPacketCollector怎麽用?Java XMPPConnection.createPacketCollector使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.jivesoftware.smack.XMPPConnection
的用法示例。
在下文中一共展示了XMPPConnection.createPacketCollector方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
}
}