Get Nickname

Hi

How would I get the Nickname of a person and display it onscreen???

I think I might have to use gerParticipant? not sure. An example would help.

Also whats the difference between PacketListener and MessageListener?

Finally how would I recieve messages only when im in chat mode?

Currently I have this code:

if( type == Message.CHAT || type == Message.NORMAL)

mytext.append(message.getBody());

The compiler says CHAT cannot be found in:

org.jivesoftware.smack.packet.Message

Thanks

Dilip

Dilip,

How would I get the Nickname of a person and display

it onscreen???

I think I might have to use gerParticipant? not sure.

An example would help.

What are you trying to achieve here? Do you need to get the name of a RosterEntry (a.k.a nickname) or do you need to get the XMPP user (e.g. jdoe@jivesoftware.com) of the participant of a chat?

In order to get the nickname of an entry you need to use RosterEntry.getName(). Whilst to get the XMPP user of the participant of a chat you need to use Chat.getParticipant(). If you need to get the nickname of the chat’'s participant then you have to do something like this:

String participant = chat.getParticipant();
RosterEntry rosterEntry = roster.getEntry(participant);
rosterEntry.getName();

Also whats the difference between PacketListener and

MessageListener?

The interface/class MessageListener does not exist. Smack expects a PacketListener wherever you see a message name like addMessageListener(listener).

Finally how would I recieve messages only when im in

chat mode?

Follow this link to learn on the different ways you have to receive chat messages. The Jive Employee Engagement Platform =76232#76232

The compiler says CHAT cannot be found in:

org.jivesoftware.smack.packet.Message

org.jivesoftware.smack.packet.Message.Type.CHAT

Regards,

– Gato

Thanks for the reply Gato.

Still got a problem I did what you said but the name comes back as null.

Any ideas?

Dilip,

The nickname of a roster entry is optional. If you are receiving an entry with no nickname then you will get a null value.

You can enable the debugging mode to check if the roster entry has a nickname or not. If you need help enabling the debugger follow this link http://www.jivesoftware.com/xmpp/smack/documentation/debugging.html.

Regards,

– Gato