Android - Smack presence and dialing features do not work

I am using the Smack library v4.1.0 (not aSmack) function to chat in an Android application. I can't seem to use the following two functions:

  • User Presence (Online, Last Time)
  • Chat message status (sent, sent, read)

For the Presence user, I use the following code, which always returns null .

 Presence userPresence = roster.getPresence(toUser); System.out.println("*** User status: " + userPresence.getStatus()); if (userPresence.getMode() == Presence.Mode.available || userPresence.getMode() == Presence.Mode.chat) { lblIsTyping.setText("Online"); } else { lblIsTyping.setText("Offline"); } 

For message status, I use the following code:

 private class MessageListenerImpl implements MessageListener, ChatStateListener { @Override public void processMessage(Chat chat, Message message) { processMessageCore(message); } @Override public void stateChanged(Chat chat, ChatState chatState) { System.out.println("*** chat: " + chat.toString()); if (ChatState.composing.equals(chatState)) { lblIsTyping.setText("typing..."); System.out.println("Chat State: " + chat.getParticipant() + " is typing.."); } } @Override public void processMessage(Message message) { processMessageCore(message); } } 

And use it like:

ChatManager.getInstanceFor(HCSmackService.getInstance().getConnection()).createChat(toUser, mThreadID, new MessageListenerImpl());

but the callback never starts.

How to make these workers work with Android with the new Smack library? Has anyone already implemented these features?

Thanks!

+8
java android chat xmpp smack
source share
1 answer
  • To receive a custom presence, you must first send an initial presence . Please note that a presence package without the type attribute is considered β€œonline”.

  • chat states are generated by the client client application. As a rule, they do not send status chats in "offline" contacts and contacts that are not "in the list".

+3
source share

All Articles