smack 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值