当前位置:首页 > 开发 > 开源软件 > 正文

smack presence问题

发表于: 2009-07-22   作者:Blackbaby   来源:转载   浏览:
摘要: Roser#getPresence(String user) will return null if the contact has no presence information available. This could be because the contact is offline or you are not subscribed to their presence  

Roser#getPresence(String user) will return null if the contact has no presence information available. This could be because the contact is offline or you are not subscribed to their presence

 

If you are getting null when your contact is online then it will be (most likely) one of two things.

 

1: Either you are not subscribed to the other contacts Presence. In which case you will need to before you are allowed to track their Online/Offline status.

 

2: As AWenckus mentioned, it can sometimes take a moment for the information to be sent so if you are performing this operation as soon as you login the method may well return null.

 

Far better to add a RosterListener to your connection to listen out for Presence changes.

 

Presence presence = (Presence)packet;
Presence.Mode presenceMode = presence.getMode();

if(presenceMode == Presence.Mode.AVAILABLE) {
    // user is online and available
}

if(presenceMode == Presence.Mode.AWAY) {
    //user is away
}
take for example two users:User A,User B

User A wants to see when User B is online.

User A sends a SUBSCRIBE packet to User B

User B then decides whether or not to allow User A to see when they are online.

If they accept the subscription requests they send a SUBSCRIBED packet

If they reject the subscription request they send a UNSUBSCRIBED packet.

 

参考:http://www.igniterealtime.org/community/message/115077#115077

smack presence问题

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号