當前位置: 首頁>>代碼示例>>Java>>正文


Java Presence.getFrom方法代碼示例

本文整理匯總了Java中org.jivesoftware.smack.packet.Presence.getFrom方法的典型用法代碼示例。如果您正苦於以下問題:Java Presence.getFrom方法的具體用法?Java Presence.getFrom怎麽用?Java Presence.getFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jivesoftware.smack.packet.Presence的用法示例。


在下文中一共展示了Presence.getFrom方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: presenceReceived

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private void presenceReceived(Presence presence){
  if (Presence.Type.available.equals(presence.getType()) &&
          presence.getStatus() != null){
    String from = presence.getFrom();
    int index = from.indexOf('@');
    if (index >= 0){
      from = from.substring(0, index);
    }
    String status = presence.getStatus();
    Intent intent = new Intent(Constants.PRESENCE_CHANGED);
    intent.putExtra(Constants.BUDDY_ID, from);
    intent.putExtra(Constants.PRESENCE_STATUS, status);
    LocalBroadcastManager.getInstance(getApplicationContext())
            .sendBroadcast(intent);
    messageHistory.setOnline(from, status);
  }
}
 
開發者ID:Nik-Sch,項目名稱:ChatApp-Android,代碼行數:18,代碼來源:MessageService.java

示例2: processPacket

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@Override
public void processPacket(Packet packet) {
	if(packet.getFrom().equals(packet.getTo())){
		return;
	}
	 if (packet instanceof Presence) {  
            Presence presence = (Presence) packet;  
            String from = presence.getFrom();//發送方  
            String to = presence.getTo();//接收方  
            if (presence.getType().equals(Presence.Type.subscribe)) {//好友申請  
                  Log.e("jj", "好友申請");
            } else if (presence.getType().equals(Presence.Type.subscribed)) {//同意添加好友  
           	 Log.e("jj", "同意添加好友");
            } else if (presence.getType().equals(Presence.Type.unsubscribe)) {//拒絕添加好友  和  刪除好友  
           	 Log.e("jj", "拒絕添加好友");
            } else if (presence.getType().equals(Presence.Type.unsubscribed)){
           	 
            } else if (presence.getType().equals(Presence.Type.unavailable)) {//好友下線   要更新好友列表,可以在這收到包後,發廣播到指定頁麵   更新列表  
           	 Log.e("jj", "好友下線");
            } else if(presence.getType().equals(Presence.Type.available)){//好友上線  
           	 Log.e("jj", "好友上線");
            }  else{
           	 Log.e("jj", "error");
            }
        }  
      }
 
開發者ID:cowthan,項目名稱:AyoSunny,代碼行數:27,代碼來源:FriendsPacketListener.java

示例3: addParticipationsListener

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * listen to new people joining the room in realtime and and set the new content which sets the component to dirty which forces it to redraw
 */
void addParticipationsListener() {
    participationsListener = new PacketListener() {

        @Override
        public void processPacket(final Packet packet) {
            final Presence presence = (Presence) packet;
            if (log.isDebugEnabled()) {
                log.debug("processPacket Presence: to=" + presence.getTo() + " , ");
            }
            if (presence.getFrom() != null) {
                listeningController.event(new InstantMessagingEvent(presence, "participant"));
            }
        }
    };
    muc.addParticipantListener(participationsListener);

}
 
開發者ID:huihoo,項目名稱:olat,代碼行數:21,代碼來源:GroupChatJoinTask.java

示例4: presenceChanged

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
/**
 * Listennig for a change in presence of the user, eg: unavailable => available
 *
 * @param presence
 */
@Override
public void presenceChanged(Presence presence) {
    String user = presence.getFrom();
    if (user.contains(xmppUserId) && presence.isAvailable()) {
        isOnline = true;
    }
}
 
開發者ID:wso2-attic,項目名稱:carbon-identity,代碼行數:13,代碼來源:XmppSubscriptionListener.java

示例5: handleSubscribed

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private void handleSubscribed(Presence p) {
    String from = StringUtils.parseName(p.getFrom());

    if (UsersProvider.getPublicKey(getContext(), from) == null) {
        // public key not found
        // assuming the user has allowed us, request it

        VCard4 vcard = new VCard4();
        vcard.setType(IQ.Type.GET);
        vcard.setTo(StringUtils.parseBareAddress(p.getFrom()));

        sendPacket(vcard);
    }

    // send a broadcast
    Intent i = new Intent(ACTION_SUBSCRIBED);
    i.putExtra(EXTRA_TYPE, Presence.Type.subscribed.name());
    i.putExtra(EXTRA_PACKET_ID, p.getPacketID());

    from = p.getFrom();
    String network = StringUtils.parseServer(from);
    // our network - convert to userId
    if (network.equalsIgnoreCase(getServer().getNetwork())) {
        StringBuilder b = new StringBuilder();
        b.append(StringUtils.parseName(from));
        b.append(StringUtils.parseResource(from));
        i.putExtra(EXTRA_FROM_USERID, b.toString());
    }

    i.putExtra(EXTRA_FROM, from);
    i.putExtra(EXTRA_TO, p.getTo());

    sendBroadcast(i);
}
 
開發者ID:ShadiNachat,項目名稱:Chatting-App-,代碼行數:35,代碼來源:PresenceListener.java

示例6: onStartCommand

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
	// TODO Auto-generated method stub
	if (null != con && con.isConnected()) {
		PacketFilter filter = new AndFilter(new PacketTypeFilter(
				Presence.class), new MessageTypeFilter(Message.Type.chat));
		PacketListener listener = new PacketListener() {
			@Override
			public void processPacket(Packet packet) {
				SLog.i("Presence", "PresenceService------" + packet.toXML());
				// 看API可知�?Presence是Packet的子�?
				if (packet instanceof Presence) {
					Presence presence = (Presence) packet;
					// Presence還有很多方法,可查看API
					String from = presence.getFrom();// 發�?�?
					String to = presence.getTo();// 接收�?
					// Presence.Type�?中狀�?
					if (presence.getType().equals(Presence.Type.subscribe)) {// 好友申請

					} else if (presence.getType().equals(
							Presence.Type.subscribed)) {// 同意添加好友

					} else if (presence.getType().equals(
							Presence.Type.unsubscribe)) {// 拒絕添加好友 �?刪除好友

					} else if (presence.getType().equals(
							Presence.Type.unsubscribed)) {// 這個我沒用到
					} else if (presence.getType().equals(
							Presence.Type.unavailable)) {// 好友下線
															// 要更新好友列表,可以在這收到包後,發廣播到指定頁�?
															// 更新列表

					} else if (presence.getType().equals(
							Presence.Type.available)) {// 好友上線

					}
				} else if (packet instanceof Message) {
					Message msg = (Message) packet;
					Toast.makeText(getApplicationContext(),
							msg.getFrom() + " 說:" + msg.getBody(),
							Toast.LENGTH_SHORT).show();
				}
			}
		};
		con.addPacketListener(listener, filter);
	}
	return super.onStartCommand(intent, flags, startId);
}
 
開發者ID:ice-coffee,項目名稱:EIM,代碼行數:49,代碼來源:PresenceService.java

示例7: handlePresence

import org.jivesoftware.smack.packet.Presence; //導入方法依賴的package包/類
private void handlePresence(Presence p) {
    Intent i = new Intent(ACTION_PRESENCE);
    Presence.Type type = p.getType();
    i.putExtra(EXTRA_TYPE, type != null ? type.name() : Presence.Type.available.name());
    i.putExtra(EXTRA_PACKET_ID, p.getPacketID());

    String from = p.getFrom();
    String network = StringUtils.parseServer(from);
    // our network - convert to userId
    if (network.equalsIgnoreCase(getServer().getNetwork())) {
        StringBuilder b = new StringBuilder();
        b.append(StringUtils.parseName(from));
        b.append(StringUtils.parseResource(from));
        i.putExtra(EXTRA_FROM_USERID, b.toString());
    }

    i.putExtra(EXTRA_FROM, from);
    i.putExtra(EXTRA_TO, p.getTo());
    i.putExtra(EXTRA_STATUS, p.getStatus());
    Presence.Mode mode = p.getMode();
    i.putExtra(EXTRA_SHOW, mode != null ? mode.name() : Presence.Mode.available.name());
    i.putExtra(EXTRA_PRIORITY, p.getPriority());

    // getExtension doesn't work here
    Iterator<PacketExtension> iter = p.getExtensions().iterator();
    while (iter.hasNext()) {
        PacketExtension _ext = iter.next();
        if (_ext instanceof DelayInformation) {
            DelayInformation delay = (DelayInformation) _ext;
            i.putExtra(EXTRA_STAMP, delay.getStamp().getTime());
            break;
        }
    }

    // non-standard stanza group extension
    PacketExtension ext = p.getExtension(StanzaGroupExtension.ELEMENT_NAME, StanzaGroupExtension.NAMESPACE);
    if (ext != null && ext instanceof StanzaGroupExtension) {
        StanzaGroupExtension g = (StanzaGroupExtension) ext;
        i.putExtra(EXTRA_GROUP_ID, g.getId());
        i.putExtra(EXTRA_GROUP_COUNT, g.getCount());
    }

    Log.v(MessageCenterService.TAG, "broadcasting presence: " + i);
    sendBroadcast(i);
}
 
開發者ID:ShadiNachat,項目名稱:Chatting-App-,代碼行數:46,代碼來源:PresenceListener.java


注:本文中的org.jivesoftware.smack.packet.Presence.getFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。