powered by Jive Software

Need to show the user status in android chat window

The below code doesn’t working. Anyone help me…

ChatManagerListenerImpl mChatManagerListener = new ChatManagerListenerImpl();

ChatManager.getInstanceFor(connection).addChatListener(

mChatManagerListener);

private class ChatManagerListenerImpl implements ChatManagerListener ,ChatStateListener

{

@Override

public void chatCreated(final org.jivesoftware.smack.chat.Chat chat,

final boolean createdLocally) {

if (!createdLocally)

chat.addMessageListener(new ChatMessageListener() {

@Override

public void processMessage(Chat chat, Message message) {

Log.i(“MyXMPP_MESSAGE_LISTENER”, “Xmpp message received: '”

  • message);

System.out.println(“Body-----”+message.getBody());

if (message.getType() == Message.Type.chat

&& message.getBody() != null) {

final ChatMessage chatMessage = new ChatMessage();

chatMessage.setBody(message.getBody());

processMessage(chatMessage);

}

}

private void processMessage(final ChatMessage chatMessage) {

chatMessage.isMine = false;

Chats.chatlist.add(chatMessage);

new Handler(Looper.getMainLooper()).post(new Runnable() {

@Override

public void run() {

Chats.chatAdapter.notifyDataSetChanged();

}

});

}

});

}

@Override

public void stateChanged(Chat chat, ChatState state) {

switch (state){

case active:

Log.d(“state”,“active”);

Chats.txtUserStatus.setText(“Active”);

break;

case composing:

Log.d(“state”,“composing”);

Chats.txtUserStatus.setText(“Typing…”);

break;

case paused:

Log.d(“state”,“paused”);

Chats.txtUserStatus.setText(“Paused”);

break;

case inactive:

Log.d(“state”,“inactive”);

Chats.txtUserStatus.setText(“Inactive”);

break;

case gone:

Log.d(“state”,“gone”);

Chats.txtUserStatus.setText(“Gone”);

break;

}

}

@Override

public void processMessage(Chat chat, Message message) {

}

}