Receiving messages from ejabberd server on Android client

Hi all,

I am trying to create an Android client using smack (4.2.4), ejabberd server (19.02) and Android SDK 25.

I followed the example app found here: https://www.blikoontech.com/tutorials/android-smack-xmpp-introductionbuilding-a-simple-client

All is working well and I can send messages between two different Android devices running that sample app.

In ejabberd, there are options to send messages to the clients directly from the server using a CLI tool called ejabberdctl or ejabberd REST API. When I send messages that way, the Android client doesn’t receive those messages. I tried with other clients like Conversations and Gajim and they could all receive it. I am pretty sure messages sent using those methods arrived because they were received as offline messages (on ejabberd web admin) when sent to offline clients. Here is the part of the Android (java) code that is to receive incoming message. Please suggest me if I am missing
anything. Thanks a lot.

ChatManager.getInstanceFor(mConnection).addIncomingListener(new IncomingChatMessageListener() {
@Override
public void newIncomingMessage(EntityBareJid messageFrom, Message message, Chat chat) {
///ADDED
Log.d(TAG,“message.getBody() :”+message.getBody());
Log.d(TAG,“message.getFrom() :”+message.getFrom());

String from = message.getFrom().toString();

String contactJid=“”;
if ( from.contains(“/”))
{
contactJid = from.split(“/”)[0];
Log.d(TAG,“The real jid is :” +contactJid);
Log.d(TAG,“The message is from :” +from);
}else
{
contactJid=from;
}

//Bundle up the intent and send the broadcast.
Intent intent = new Intent(RoosterConnectionService.NEW_MESSAGE);
intent.setPackage(mApplicationContext.getPackageName());
intent.putExtra(RoosterConnectionService.BUNDLE_FROM_JID,contactJid);
intent.putExtra(RoosterConnectionService.BUNDLE_MESSAGE_BODY,message.getBody());
mApplicationContext.sendBroadcast(intent);
Log.d(TAG,“Received message from :”+contactJid+" broadcast sent.");
///ADDED

}
});

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.