powered by Jive Software

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() {
public void newIncomingMessage(EntityBareJid messageFrom, Message message, Chat chat) {
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);

//Bundle up the intent and send the broadcast.
Intent intent = new Intent(RoosterConnectionService.NEW_MESSAGE);
Log.d(TAG,“Received message from :”+contactJid+" broadcast sent.");


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