powered by Jive Software

Smack presence getting problem

Hi,

I am new to the smack API.I am developing Google Talk Application.In my Application while getting Friends Status i am able to get dnd and away but i am not able to get available,chat.What is the problem i am not able to find that.If you any body knows the problem where please give me reply Thanks.

I am also attatching code here.

ConnectionConfiguration connConfig = new ConnectionConfiguration(“talk.google.com”, 5222, “gmail.com”);
connConfig.setSASLAuthenticationEnabled(false);//with out this line i am not able to login i.e why i included here
XMPPConnection xmppConnection = new XMPPConnection(connConfig);

xmppConnection.connect();

xmppConnection.login(userName,passWord);
Presence presence = new Presence(Presence.Type.available);
presence.setStatus(“I am in Office”);
presence.setPriority(24);
xmppConnection.sendPacket(presence);

try
{
Thread.sleep(5000);
}catch(Exception e){}

Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
Roster roster = xmppConnection.getRoster();
Collection entries = roster.getEntries();

        //System.out.println("---------Enter into get friends------");
        for (RosterEntry entry : entries)

{

                  Presence pres = roster.getPresence(entry.getUser());              
           
        
                      if(pres.getMode()!=null)
                         {
                                   System.out.println(entry.getUser()+"    :"+pres.getMode()+"\n");
                                    System.out.println("\n");
                       }

}

Here Even Some of friends are in online the code is showing unavailbale.If busy,away it is showing correctly.Is there any Bug in Smack Api it self.

please reply any one Thanks

Message was edited by: madhusudhan dumpa

When you login you make :

Presence presence = new Presence(Presence.Type.available);
presence.setStatus(“I am in Office”);
presence.setPriority(24);
xmppConnection.sendPacket(presence);

I think you should add this before sending the packet (available or other) :

presence.setMode(Presence.Mode.available);

I’m using this way and i don’t have any matter… But sometimes PresencePacket are wrong and i’ve put a ListenerPresence to be sure of results in realtime…

Hi,

Even I put presence.setMode(Presence.Mode.available) before sending packet i am not getting online available friends status but i am getting away,dnd friends status.is there some thing to change in code please reply me.T

Thanks

Madhusudhan

Hum… sometimes Presence packet sending by OpenFire are wrong… and the mode are not write in the packet… To resolve this matter, I have put the mode in a string format in the status field. And i have a listener for presence packet which decode the status field. Here an example for the sending of the packet:

presence.setStatus(“available”+’::’+monstatut);

xmppConnection.sendPacket(presence);

Here the listener :

public class PresencePacketListener implements PacketListener{

public void processPacket(Packet packet) {

if(!(packet instanceof Presence)){

return;

}

Presence presence = (Presence)packet;

if(presence.getMode() != null){

status = presence.getMode();

}else if(status != null){

status = presence.getStatus().split("::")[0];

}

Hope that’ll be helpful for you

public class PresencePacketListener implements PacketListener{

Hi,

I am not aware of openfire and all just i am developing client application in Android mobile.I am using talk.google.com service only.What is that Open fire it is one og the Api right or is itself server?

Thanks,

Madhusudhan

Hum ok you are using smack for android… Despite that the matter could be the same… do you have tested the solution above (with presencePacketListener) ?

Openfire is a XMPP server developped by the same guy that are developping smack.

Hope that answer you’re question

Hi @Aurélien,

Sorry yaar i am not able to get what you told .I tried but no result.Here I am setting default subscription mode.Actually iam not able to get Available (Green) friends ,i am getting as unavailable.Can you send me the code snippet to retrieve all friends Ststus in Gtalk.

Thanks,

Madhusudhan

I don’t know the code for status in GTalk… look at this link : http://www.adarshr.com/papers/xmpp2

One paragraph talking about presence… maybe that could help you… because i’ve no other idea…

Hi,

Sorry for disturbing …In that Link only Upto how to set presence is there.But i want to display All my friends presence avaialbe or dnd or away in my application.My main problem is I am getting the users presence Away,dnd only i am not getting Available friends presence.If u are aware u intimate o.w no need.Any way thanks for your help

thanks,

madhusudhan

In the link it’s written that there aren’t status “available” but the status “chat” is used for indicates that the contact is available… did you try with “chat” ?