本文整理汇总了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);
}