本文整理汇总了Java中org.jivesoftware.smack.Roster.SubscriptionMode类的典型用法代码示例。如果您正苦于以下问题:Java SubscriptionMode类的具体用法?Java SubscriptionMode怎么用?Java SubscriptionMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SubscriptionMode类属于org.jivesoftware.smack.Roster包,在下文中一共展示了SubscriptionMode类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LolChat
import org.jivesoftware.smack.Roster.SubscriptionMode; //导入依赖的package包/类
/**
* Represents a single connection to a League of Legends chatserver.
*
* @param server
* The chatserver of the region you want to connect to
* @param friendRequestPolicy
* Determines how new Friend requests are treated.
* @param riotApiKey
* Your apiKey used to convert summonerId's to name. You can get
* your key here <a
* href="https://developer.riotgames.com/">developer
* .riotgames.com</a>
*
* @see LolChat#setFriendRequestPolicy(FriendRequestPolicy)
* @see LolChat#setFriendRequestListener(FriendRequestListener)
*/
public LolChat(ChatServer server, FriendRequestPolicy friendRequestPolicy,
RiotApiKey riotApiKey) {
this.friendRequestPolicy = friendRequestPolicy;
this.server = server;
if (riotApiKey != null && server.api != null) {
this.riotApi = RiotApi.build(riotApiKey, server);
}
Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
final ConnectionConfiguration config = new ConnectionConfiguration(
server.host, 5223, "pvp.net");
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
config.setSocketFactory(SSLSocketFactory.getDefault());
config.setCompressionEnabled(true);
connection = new XMPPTCPConnection(config);
addListeners();
}
示例2: processPacket
import org.jivesoftware.smack.Roster.SubscriptionMode; //导入依赖的package包/类
@Override
public void processPacket(Packet packet) {
String user = getSharedPreferences(Constant.LOGIN_SET, 0)
.getString(Constant.USERNAME, null);
if (packet.getFrom().contains(user))
return;
// ������Զ���������������ظ�һ�������Ϣ
if (Roster.getDefaultSubscriptionMode().equals(
SubscriptionMode.accept_all)) {
Presence subscription = new Presence(Presence.Type.subscribe);
subscription.setTo(packet.getFrom());
XmppConnectionManager.getInstance().getConnection()
.sendPacket(subscription);
} else {
NoticeManager noticeManager = NoticeManager
.getInstance(context);
Notice notice = new Notice();
notice.setTitle("��������");
notice.setNoticeType(Notice.ADD_FRIEND);
notice.setContent(StringUtil.getUserNameByJid(packet.getFrom())
+ "�����������");
notice.setFrom(packet.getFrom());
notice.setTo(packet.getTo());
notice.setNoticeTime(DateUtil.date2Str(Calendar.getInstance(),
Constant.MS_FORMART));
notice.setStatus(Notice.UNREAD);
long noticeId = noticeManager.saveNotice(notice);
if (noticeId != -1) {
Intent intent = new Intent();
intent.setAction(Constant.ROSTER_SUBSCRIPTION);
notice.setId("" + noticeId);
intent.putExtra("notice", notice);
sendBroadcast(intent);
setNotiType(R.drawable.icon, "��������",
StringUtil.getUserNameByJid(packet.getFrom())
+ "�����������", MyNoticeActivity.class);
}
}
}
示例3: init
import org.jivesoftware.smack.Roster.SubscriptionMode; //导入依赖的package包/类
/**
* Initializing the XMPPListener. Retrieve connection details provided in
* xmpp transport receiver, connect to those servers & start listening in
* for messages.
*/
public void init(ConfigurationContext configurationCtx, TransportInDescription transportIn)
throws AxisFault {
log.info("Initializing XMPPListener...");
//allow anyone to send message to listening account
Roster.setDefaultSubscriptionMode(SubscriptionMode.accept_all);
configurationContext = configurationCtx;
initializeConnectionFactories(transportIn);
if (connectionFactories.isEmpty()) {
log.warn("No XMPP connection factories defined." +
"Will not listen for any XMPP messages");
return;
}
}
示例4: LolChat
import org.jivesoftware.smack.Roster.SubscriptionMode; //导入依赖的package包/类
/**
* Represents a single connection to a League of Legends chatserver.
*
* @param server The chatserver of the region you want to connect to
* @param friendRequestPolicy Determines how new Friend requests are treated.
* @param riotApiKey Your apiKey used to convert summonerId's to name. You can get
* your key here <a
* href="https://developer.riotgames.com/">developer
* .riotgames.com</a>
* @see LolChat#setFriendRequestPolicy(FriendRequestPolicy)
* @see LolChat#setFriendRequestListener(FriendRequestListener)
*/
public LolChat(ChatServer server, FriendRequestPolicy friendRequestPolicy,
String riotApiKey) {
this.friendRequestPolicy = friendRequestPolicy;
if (riotApiKey != null && server.api != null) {
this.riotApi = new JRiot(riotApiKey, server.name().toLowerCase());
}
Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
final ConnectionConfiguration config = new ConnectionConfiguration(
server.host, 5223, "pvp.net");
config.setSecurityMode(ConnectionConfiguration.SecurityMode.enabled);
config.setSocketFactory(SSLSocketFactory.getDefault());
config.setCompressionEnabled(true);
connection = new XMPPTCPConnection(config);
try {
connection.connect();
} catch (Exception e) {
System.err.println("Failed to connect to " + server.host);
return;
}
addListeners();
new Thread(new Runnable() {
@Override
public void run() {
while (!stop) {
try {
Thread.sleep(500);//NOT SURE ABOUT THIS, TODO:REVIST
} catch (final InterruptedException ignored) {
}
}
}
}).start();
}
示例5: connect
import org.jivesoftware.smack.Roster.SubscriptionMode; //导入依赖的package包/类
private boolean connect()
{
final String server = config.getString("xmpp.server");
if (server == null || server.equals("example.com"))
{
LOGGER.log(Level.WARNING, "config broken for xmpp");
return false;
}
final int port = config.getInt("xmpp.port", 5222);
final String serviceName = config.getString("xmpp.servicename", server);
final String xmppuser = config.getString("xmpp.user");
final String password = config.getString("xmpp.password");
final ConnectionConfiguration connConf = new ConnectionConfiguration(server, port, serviceName);
final StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Connecting to xmpp server ").append(server).append(":").append(port);
stringBuilder.append(" as user ").append(xmppuser).append(".");
LOGGER.log(Level.INFO, stringBuilder.toString());
connConf.setSASLAuthenticationEnabled(config.getBoolean("xmpp.sasl-enabled", false));
connConf.setSendPresence(true);
connConf.setReconnectionAllowed(true);
connection = new XMPPConnection(connConf);
try
{
connection.connect();
connection.login(xmppuser, password);
connection.getRoster().setSubscriptionMode(SubscriptionMode.accept_all);
chatManager = connection.getChatManager();
chatManager.addChatListener(this);
return true;
}
catch (XMPPException ex)
{
LOGGER.log(Level.WARNING, "Failed to connect to server: " + server, ex);
return false;
}
}
示例6: processPacket
import org.jivesoftware.smack.Roster.SubscriptionMode; //导入依赖的package包/类
@Override
public void processPacket(Packet packet) {
Log.i("TAG", "[服务]收到联系人消息:"+packet.getFrom());
//在登录中保存的
String user = getSharedPreferences(IMConstant.IMSHARE, 0)
.getString(IMConstant.USERNAME, null);
if (packet.getFrom().contains(user))
return;
// 如果是自动接收所有请求,则回复一个添加信息
if (Roster.getDefaultSubscriptionMode().equals(
SubscriptionMode.accept_all)) {
Presence subscription = new Presence(Presence.Type.subscribe);
subscription.setTo(packet.getFrom());
IMUtil.getXMPPConnection()
.sendPacket(subscription);
} else {
// 生成消息历史记录
IMMessage mIMMessage = new IMMessage();
mIMMessage.setTitle("好友请求");
String from = IMUtil.getUserNameByJid(packet.getFrom());
mIMMessage.setContent(from + "申请加您为好友");
Log.i("TAG", "[服务]收到好友请求:"+from + "申请加您为好友");
mIMMessage.setSendState(IMMessage.RECEIVED);
mIMMessage.setType(IMMessage.ADD_FRIEND_MSG);
//发送方
mIMMessage.setUserName(from);
//接收方
mIMMessage.setToUserName(IMUtil.getUserNameByJid(packet.getTo()));
mIMMessage.setReadState(IMMessage.UNREAD);
mIMMessage.setRequestState(IMMessage.ALL);
String time = AbDateUtil.getCurrentDate(AbDateUtil.dateFormatYMDHMS);
mIMMessage.setTime(time);
//保存本地
mIMMsgDao.startWritableDatabase(false);
long messageId = mIMMsgDao.insert(mIMMessage);
mIMMsgDao.closeDatabase();
if (messageId != -1) {
//发出接收到会话的消息
Intent intent = new Intent();
intent.setAction(IMConstant.ACTION_ROSTER_SUBSCRIPTION);
intent.putExtra("MESSAGE", mIMMessage);
sendBroadcast(intent);
}
}
}
示例7: onCreate
import org.jivesoftware.smack.Roster.SubscriptionMode; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void onCreate() {
super.onCreate();
registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
mSettings = PreferenceManager.getDefaultSharedPreferences(this);
mSettings.registerOnSharedPreferenceChangeListener(mPreferenceListener);
if (mSettings.getBoolean(BeemApplication.USE_AUTO_AWAY_KEY, false)) {
mOnOffReceiverIsRegistered = true;
registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));
}
String tmpJid = mSettings.getString(BeemApplication.ACCOUNT_USERNAME_KEY, "").trim();
mLogin = StringUtils.parseName(tmpJid);
boolean useSystemAccount = mSettings.getBoolean(BeemApplication.USE_SYSTEM_ACCOUNT_KEY, false);
mPort = DEFAULT_XMPP_PORT;
mService = StringUtils.parseServer(tmpJid);
mHost = mService;
initMemorizingTrustManager();
if (mSettings.getBoolean(BeemApplication.ACCOUNT_SPECIFIC_SERVER_KEY, false)) {
mHost = mSettings.getString(BeemApplication.ACCOUNT_SPECIFIC_SERVER_HOST_KEY, "").trim();
if ("".equals(mHost))
mHost = mService;
String tmpPort = mSettings.getString(BeemApplication.ACCOUNT_SPECIFIC_SERVER_PORT_KEY, "5222");
if (!"".equals(tmpPort))
mPort = Integer.parseInt(tmpPort);
}
if (mSettings.getBoolean(BeemApplication.FULL_JID_LOGIN_KEY, false)
|| "gmail.com".equals(mService) || "googlemail.com".equals(mService)
|| useSystemAccount) {
mLogin = tmpJid;
}
configure(ProviderManager.getInstance());
mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
mBind = new XmppFacade(this);
Log.d(TAG, "Create BeemService");
}