Not able to send messages using smack 4.1.3 from android emultor

HI Guys

Please help me. I am developing android xmpp Client using Smack 4.1.3 + Openfire 3.10.2 server. I am able to receive the messages sent from SPARK windows client but not able send the message to the same. Kindly help me… here is my code :

public void sendMessage(String buddyJID, String messageTe) {

String OurBuddy = buddyJID + “@” + ChatContants.SERVICENAME;

String from = connection.getUser();



“Connection is null in sendMessage Sending mesage ‘%1$s’ to user %2$s from Me %3$s”,

messageTe, OurBuddy, from));

if (chatManager != null) {

Message msgObj = new Message();





msgObj.addExtension(new DefaultExtensionElement(“from”, from));

msgObj.addExtension(new DefaultExtensionElement(“to”, OurBuddy));

try {


///LOgs sent message

} catch (NotConnectedException e) {

// TODO Auto-generated catch block

Log.d(TAG, “sendStanza is creating some problem”);



} else {

Log.d(TAG, “XMPPMANGER sendMEssage chamAnaeger is Null”);



ChatContants.SERVICENAME is same as provided in openfire domain name,

Already connected and logged in.

I am getting the sent message logs but not receiving any thing in SPARK client.

can you give me you code ,i havn’t mean

Please find the attached code.

put all libraries of smack 4.1.3 and use your server and domain name in ChatContants class…

Please help me …

Also provide some suggestion for better functioning of this chat app. It is in its beginning phase of development.

Thanx in advance. (152774 Bytes)


this code doesn’t send a message

//get a chatmanager

ChatManager cm = ChatManager.getInstanceFor(connection);

//add listener

// if receive a message ,this will get

cm.addChatListener(new ChatManagerListener(){


public void chatCreated(Chat arg0, boolean arg1) {

arg0.addMessageListener(new ChatMessageListener(){


public void processMessage(Chat arg0, Message arg1) {



String from = arg1.getFrom().substring(0,arg1.getFrom().indexOf("@"));

System.out.println("from “+from+” : "+arg1.getBody());






//this send a mesage to someone

Chat chat = cm.createChat("zxc@");


i use this function ,can send a message to someone

which version jdk??

Use samck4.1.4 android as above must use jdk7 version?

Thnx for reply @zhengxiujiang

I am using java version “1.8.0_31” ,

I also try to send message as you have suggested.

but I have used my openfire server domain name instead of IP Address in JID.(I think it should be fine.)

Chat chat = cm.createChat(“zxc@domain-pc”);


still not able to send messages to the server while I am perfectly receiving the messages.

i think of it

Chat chat = cm.createChat(“zxc@domain-pc”);

This “domain-pc” is your service name.


It is this properties

not you host.

Hey @zhengxiujiang

I got the problem …

I added a code line xmmpManager.getConnection().getUser() and it return **NULL **(which indicates that I am logged out of server) But openfire server shows that I am still logged in .

Thats why I was unable to send Message.

Now for a workaround, I added login code before each message send code… But it is returning me AlreadyLoggedInException in try catch.

and message is successfully sent to the client.

Please help me… How can I avoid such scenerios.


This is my code for send messages for individual chat:

public boolean sendmessage(String body, String destinationuser){

String from = mConnection.getUser();

ChatManager chatManager = ChatManager.getInstanceFor(mConnection);

Message message = new Message(destinationuser,;



message.addExtension(new DefaultExtensionElement(“from”,from));

message.addExtension(new DefaultExtensionElement(“to”, destinationuser));

try {


} catch (SmackException.NotConnectedException e) {


return false;


return true;


You don’t need add login code before each message send code. Only when the user is offline.