Android - Smack presence and "is typing" features not working
Asked Answered
O

1

8

I'm using the Smack library v4.1.0 (not aSmack) for Chat feature within an android app. I can't seem to get the following two feature to work:

  1. User Presence (Online, Last Seen)
  2. Chat Message Status (Sent, Delivered, Read)

For User Presence, 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 as:

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

but the callback doesn't get invoked ever.

How to get these working on Android with the new Smack Library? Has anybody already implemented these features?

Thanks!

Overrefinement answered 5/10, 2015 at 7:42 Comment(1)
You are able to get online or offline Status when User is try to Online and Offline with same connection as receiver works but you have to maintain the Last Seen From Your Codding Side.Pudendum
K
3
  1. In order to receive user presences you need to send initial presence first. Note, presence packet without type attribute considered to be "online" presence.

  2. Chat states are generated by your buddy's client application. Typically they not send chat states to "offline" contacts and contacts who are not "in roster".

Kobarid answered 12/10, 2015 at 11:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.