0
votes

I'm playing around with Smack for Android to create a simple chat client. I use ejabberd as a local XMPP server. The basics seem to work just fine: I can connect, receive and send messages. For testing I use Gajim/PSI as off-the-shelf XMPP clients.

My only problem is that the Android user is always listed as offline in Gajim and PSI. Since exchanging messages works, the Android user is obviously connected, and the ejabberd Web admin interface lists both users as connected.

In my Andoird code, after connecting and logging in, I send a presence stanza like this:

...
stanza = new Presence(Presence.Type.available);
stanza.setStatus("online");
this.mConnection.sendStanza(stanza);
...

I see this stanze in ejabberd using live mode. I thought that would tell Gajim/PSI that the user is online. Or is it required that the Android user first needs to add the Gajim/PIS user explicitly to its roster? I'm currently not doing that.

1

1 Answers

2
votes

For presence status to work in xmpp both the users should be subscribed to each other.

On sender side:

Presence presence = new Presence(Presence.Type.subscribe);
presence.setTo(receiverJid);
connection.sendPacket(presence);

On Receiver side:

Presence subscribed = new Presence(Presence.Type.subscribed);
subscribed.setTo(senderJid);
connection.sendPacket(subscribed);

Repeat the above for both users. They should be mutually subscribed. If you do it for one user it won't work