Show me the code! – By Davanum Srinivas

December 31, 2007

Android – Just use Smack API for XMPP

Filed under: Uncategorized — Davanum Srinivas @ 9:36 am

OUTDATED SAMPLE – Updated code is here:


https://davanum.wordpress.com/2008/12/29/updated-xmpp-client-for-android/

Using Smack XMPP API from Android

Once you get tired of the limitations of android’s built-in IMProvider and the corresponding API – IXmppSession and IXmppService, try the sample below. Inside the source/binary zip (bottom of this article) you will find a smack.jar that works with android. To build the jar yourself, You can download the Smack 3.0.4 sources from here and apply the patch here.

Here is a screen shot of the XMPP Settings Dialog.

1

Notes



  • For GTalk, use “gtalk.google.com” as host with port 5222. The service name is “gmail.com”

  • Don’t add “@gmail.com” in the user name, just the id will do

Here’s the code for the settings dialog

package org.apache.android.xmpp;

import android.app.Dialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;

/**
 * Gather the xmpp settings and create an XMPPConnection
 */
public class SettingsDialog extends Dialog implements android.view.View.OnClickListener {
    private XMPPClient xmppClient;

    public SettingsDialog(XMPPClient xmppClient) {
        super(xmppClient);
        this.xmppClient = xmppClient;
    }

    protected void onStart() {
        super.onStart();
        setContentView(R.layout.settings);
        getWindow().setFlags(4, 4);
        setTitle("XMPP Settings");
        Button ok = (Button) findViewById(R.id.ok);
        ok.setOnClickListener(this);
    }

    public void onClick(View v) {
        String host = getText(R.id.host);
        String port = getText(R.id.port);
        String service = getText(R.id.service);
        String username = getText(R.id.userid);
        String password = getText(R.id.password);

        // Create a connection
        ConnectionConfiguration connConfig =
                new ConnectionConfiguration(host, Integer.parseInt(port), service);
        XMPPConnection connection = new XMPPConnection(connConfig);

        try {
            connection.connect();
            Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost());
        } catch (XMPPException ex) {
            Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + connection.getHost());
            xmppClient.setConnection(null);
        }
        try {
            connection.login(username, password);
            Log.i("XMPPClient", "Logged in as " + connection.getUser());

            // Set the status to available
            Presence presence = new Presence(Presence.Type.available);
            connection.sendPacket(presence);
            xmppClient.setConnection(connection);
        } catch (XMPPException ex) {
            Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username);
            xmppClient.setConnection(null);
        }
        dismiss();
    }

    private String getText(int id) {
        EditText widget = (EditText) this.findViewById(id);
        return widget.getText().toString();
    }
}

Here is a screen shot of the main window.

1

Notes



  • In the Recipient field, make sure you add the “@gmail.com”, not just the user id

Here’s the code for the main activity

package org.apache.android.xmpp;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.MessageTypeFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.util.StringUtils;

import java.util.ArrayList;

public class XMPPClient extends Activity {

    private ArrayList<String> messages = new ArrayList();
    private Handler mHandler = new Handler();
    private SettingsDialog mDialog;
    private EditText mRecipient;
    private EditText mSendText;
    private ListView mList;
    private XMPPConnection connection;

    /**
     * Called with the activity is first created.
     */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        mRecipient = (EditText) this.findViewById(R.id.recipient);
        mSendText = (EditText) this.findViewById(R.id.sendText);
        mList = (ListView) this.findViewById(R.id.listMessages);
        setListAdapter();

        // Dialog for getting the xmpp settings
        mDialog = new SettingsDialog(this);

        // Set a listener to show the settings dialog
        Button setup = (Button) this.findViewById(R.id.setup);
        setup.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                mHandler.post(new Runnable() {
                    public void run() {
                        mDialog.show();
                    }
                });
            }
        });

        // Set a listener to send a chat text message
        Button send = (Button) this.findViewById(R.id.send);
        send.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String to = mRecipient.getText().toString();
                String text = mSendText.getText().toString();

                Log.i("XMPPClient", "Sending text [" + text + "] to [" + to + "]");
                Message msg = new Message(to, Message.Type.chat);
                msg.setBody(text);
                connection.sendPacket(msg);
                messages.add(connection.getUser() + ":");
                messages.add(text);
                setListAdapter();
            }
        });
    }

    /**
     * Called by Settings dialog when a connection is establised with the XMPP server
     *
     * @param connection
     */
    public void setConnection
            (XMPPConnection
                    connection) {
        this.connection = connection;
        if (connection != null) {
            // Add a packet listener to get messages sent to us
            PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
            connection.addPacketListener(new PacketListener() {
                public void processPacket(Packet packet) {
                    Message message = (Message) packet;
                    if (message.getBody() != null) {
                        String fromName = StringUtils.parseBareAddress(message.getFrom());
                        Log.i("XMPPClient", "Got text [" + message.getBody() + "] from [" + fromName + "]");
                        messages.add(fromName + ":");
                        messages.add(message.getBody());
                        // Add the incoming message to the list view
                        mHandler.post(new Runnable() {
                            public void run() {
                                setListAdapter();
                            }
                        });
                    }
                }
            }, filter);
        }
    }

    private void setListAdapter
            () {
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                R.layout.multi_line_list_item,
                messages);
        mList.setAdapter(adapter);
    }
}

Download Source and APK from here – XMPPClient.zip

97 Comments »

  1. Hey Srini,

    Great job! We are building a app for Android around XMPP and other Android services. this is cool stuff.

    Thanks,
    Sunil

    Comment by Sunil Vishnubhotla — January 2, 2008 @ 8:53 am

  2. Thanks Sunil,
    If anyone has trouble building the JARs, get kxml2 from here and place it in build/merge/ This should help.

    Comment by Blago — January 3, 2008 @ 1:23 pm

    • Hello Sunil,

      Could you please send me the patched smack.jar?

      that will be very much appreciated.

      thanks in advance.

      Joseph.

      Comment by Joseph — April 15, 2010 @ 12:07 pm

  3. Hi, Davanum,

    how did you get to compile 3rd party JAR file to Android platform? Could you list your steps? Thanks a lot in advance.

    Andrew

    Comment by Andrew — January 4, 2008 @ 3:32 pm

  4. The funny thing is that Android is using smack library underneath. You can see it by taking a look at XMPPService dex code.

    Comment by simeon — January 6, 2008 @ 4:34 pm

  5. […] to watch that evolve as they flesh out the platform details. [edit: look like people are figuring out how to get around Google’s artificial limitations] It could be a very interesting platform for […]

    Pingback by candyspark* » Blog Archive » Status Update, Jan 2008 — January 7, 2008 @ 11:42 am

  6. Well, Android itself is using the smack library 🙂

    Comment by Russian Translit — January 10, 2008 @ 8:49 pm

  7. Have you had any issues with some of the smackx packages?

    It looks like its not loading the classes so things like ServiceDiscoverManager don’t work properly.

    Comment by Mike Ryan — January 11, 2008 @ 5:05 pm

  8. Great package! I tried to connect to a lokal openfire server but it failed. If I use your smack.jar together with android.jar outside the emulator it works fine. Are there some limitations (only connections to google talk server) inside the emulator?

    Comment by Markus — January 16, 2008 @ 3:06 am

  9. Found a workaround for the error descibed before: The Android platform seems not to use DNS entries in the hosts file (tested on Windows Vista and XP).

    Nether 127.0.0.1 nor “localhost” nor any other entry directing on the loopback address works. When I use the lokal address in my lokal network it’s runing fine and the connection can be established.

    Comment by Markus — January 16, 2008 @ 9:36 am

  10. Android – Just use Smack API for XMPP

    0
    vote

    Once you get tired of the limitations of android’s built-in IMProvider and the corresponding API – IXmppSession and IXmppService, try the sample below. Inside the source/binary zip (bottom of this article) you will find a smack.jar that work

    Trackback by Go to Android — January 17, 2008 @ 4:44 am

  11. When I run this application, it gives me an error
    NullPointerException

    Comment by Natasha — January 24, 2008 @ 6:00 am

  12. Markus, what exactly do you mean by “When I use the lokal address in my lokal network it’s runing fine and the connection can be established.” ??

    Please help me if you know the answer. I understand redirecting the traffic from host port to guest port, but here the client is running on android, but it wont connect to the server- using the server name/hostname/ip address.

    Comment by Natasha — January 30, 2008 @ 6:14 am

  13. @Natasha: Just use the IP address of the computer where the xmpp server is running.

    If you are running xmpp server and android emulator on the same machine use the external IP address of the computer to connect. The loopback address (“localhost”, 127.0.0.1, etc.) does not work. I think android is resolving “localhost” to it self.

    Comment by Markus — February 3, 2008 @ 7:59 am

  14. Hi Guys, taking the XMPPClient.zip from above and running it through my emulator through Eclipse, I get a series of warnings like the following: W/dalvikvm(556): Link of class 'org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow$PopupListener' failed. The app comes up, yet testing sending messages I get nothing sent. I tried also adding to the project the smackx.jar file, but then I get errors about classes already being loaded. I’m using the following configs: talk.google.com 5222 gmail.com organic2@gmail.com . Can someone shed some some light on what might be going on here? Thanks.

    Comment by MikeO — February 4, 2008 @ 4:13 pm

  15. quick correction, my userid is just organic2, no @gmail.com, per the instructions above.

    Comment by MikeO — February 4, 2008 @ 4:15 pm

  16. Ok, update; I can send messages to GTalk, so I can have a conversation between a gtalk client and my android emulator. I would like to go phone to phone, or emulator to emulator in this case. I’ve scoured the user groups for this, anyone have an idea on how to do this?

    Comment by MikeO — February 4, 2008 @ 4:59 pm

  17. @MikeO: All smackx classes are compiled into the smack.jar above. That’s why you get the error messages after adding smackx.jar.

    The error message “W/dalvikvm(556): Link of class ‘org/jivesoftware/smackx/debugger/EnhancedDebuggerWindow$PopupListener’ failed.” is thrown because the debugger window requiring some java.awt classes not included in android is also compiled within.

    Based on Davanum’s patch I’ve compiled a new lightweight smack.jar where all these classes were removed. You can download the new jar file here.

    Comment by Markus — February 9, 2008 @ 8:36 am

  18. Markus, thank you for replying to my query. Really appreciate it.
    I tried using the local ip address of the machine where the OpenFire server is installed, but it gave me exception ‘No response from server’. Then I replaced the openfire server with gtalk and then with Jabberd 2 server, same result. And I’m sure the credentials are correct, logs in with a commercial client, but when I try from my Java client, just doesnt go past the ‘No response..’ error. And the code is exactly similar to the one above.

    If possible, please help.
    Thanks.

    Comment by Natasha — February 13, 2008 @ 6:48 am

  19. Natasha, do you get the error message “No response from the server.” or “No response from server.”? There are two different types of messages in the smack package.

    The first exception is thrown during the authentification process. Is your internet connection very slow? Smack waits only 5 seconds for a reply of the server and then the exception is thrown. Try to increase the packet reply timeout. The static method

    SmackConfiguration.setPacketReplyTimeout(15000);

    will set the timeout to 15 seconds. Set the timeout before connection.connect().

    Comment by Markus — February 14, 2008 @ 3:33 pm

  20. Hi, Could anyone please tell me how to use the above code, I mean step wise explaination of how to implement it?
    Please help me.

    Comment by Sonal — February 15, 2008 @ 8:26 am

  21. I am also encountering the null pointer exception. I built it using the new android sdk under eclipse. Launched the emulator OK. In the set up screen I set the host to talk.google.com port 5222, specified my gmail ID and password and pressed OK. After ‘thinking’ for a while the emulator came back with the chat window. In there I specified the recipient (another gmail account that’s logged into gtalk from a desktop, with full ‘____@gmail.com’ address), and tried to send it a message. When I clicked the “send” button I got a null pointer exception in org.apache.android.xmpp. From the desktop side, the gtalk application did not recognize that the emulator account was logged in, either.

    Please advice if possible. Thanks.

    Comment by anon8mizer — February 21, 2008 @ 4:28 am

  22. the question still remain from previous version of unofficial gtalk client, is this version capable to receiving text message from gtalk client? please advise

    Comment by enshrentko — February 27, 2008 @ 5:24 am

  23. i got the error “not connected to server” when trying to setting the connection, please advise

    Comment by enshrentko — February 27, 2008 @ 8:44 am

  24. And what about an Android-Jingle app.?

    Comment by Rodrigo — March 8, 2008 @ 11:37 am

  25. Could you try to update this sample for the latest android SDK please?

    Comment by Joseph Dung — March 11, 2008 @ 6:09 am

  26. Thanks! This is a great program.

    To Joseph Dung:

    The only thing you need to modify is the layout of the program. After you add “android” in front of each “id:”
    this program can run.

    Comment by Luke — March 25, 2008 @ 11:07 am

  27. Hello,

    thank you for this API porting, srinivas. It is at the heart of my entire project 🙂

    For anyone that might still be interrested in this API, have you guys tried out the example in the debugger ? And if you did, what were the results ?
    For me it works ok when i run the example, but when i try debugging it, it connects ok to the xmpp server (tried with talk.google.com and jabber.org). When stepping over

    “connection.login(username, password);”

    line the debugger waits for the 5 seconds default timeout of smack API and catches an xmppException. And it also says in its output window:

    “ERROR/OpenSSLSocketImpl(1234): SSL handshake failure (return code 0; error code 5; errno 0)”

    It makes no difference if I set a longer timeout. Just 5 minutes ago I have noticed that it can also connect from debugger if I press the Ok button again in the SettingsDialog form x-).
    Yes, if I “connect twice” from the debugger, I get my user connected and logged in to my server. lol ???

    Thanks

    Comment by kellogs — March 31, 2008 @ 7:13 pm

  28. Hi Davanum,
    I tried the source code for XXMP,its giving runtime error org/jivesoftware/smack/connectionConfiguration while trying to create ConnectionConfiguration connConfig =
    new ConnectionConfiguration(“talk.google.com”, 5222, “gmail.com”);
    Please let me know what can be possible error.

    Comment by anup tiwary — April 2, 2008 @ 12:27 am

  29. Hi there

    I get an XMPPException in Line 46 when trying to connect to talk.google.com (i.e. IP: 209.85.137.125). Any idea why?

    Greetz
    Graphity

    Comment by Graphity — April 10, 2008 @ 5:04 am

  30. Hi again

    I fired up my debugger, played around and found out that the exception comes from org.jivesoftware.smack.PacketRead Line 164 (it must be around there, I changes the code a little). The line says ‘throw new XMPPException(“Connection failed. No response from server.”);’ when connectionID == null.
    BUT, that connectionID is set in parsePackets(Thread) which is never called (or is it?).

    Any ideas what I can do?

    Comment by Graphity — April 10, 2008 @ 9:18 am

  31. Ok, I figured parsePackets(Thread) is called when init() is called. So do I get an XMPPException?

    Comment by Graphity — April 11, 2008 @ 3:41 am

  32. I am a beginner…. I dont know how to apply patch for the xmpp connection. I am getting Connenction configuration error.i.e, connection itself not getting established……. What is the error … Plz any one reply…
    Thanks.

    Comment by Gunaa — April 22, 2008 @ 8:00 am

  33. Please provide XMPPClient.zip with the patch

    Comment by Tinky — September 5, 2008 @ 1:52 am

  34. Hi. I hope this threat is already open. The XMPPClient.zip is no longer available. I build the client by my self, but i dont have the correct smack.jar file. And i don’t know how i can patch the original. Can anyone upload the XMPPClient.zip or patched smack.jar again?

    Comment by Bulldog — September 18, 2008 @ 4:09 am

  35. Hello,

    I have tried same code, i am getting error message on the program GMailSender.java, line is static {
    Security.addProvider(new org.apache.harmony.xnet.provider.jsse.JSSEProvider());
    }
    the error message is org.apache.harmony cannot be ressolved as type..

    is there any dependancies need to be installed to run an application.

    Thanks in Advance

    Regard’s
    Parasuraman.K

    Comment by Parasuram — October 6, 2008 @ 7:32 am

  36. Hey anyone has the updated zip file for SDK 1.0.

    Comment by indiabolbol — October 17, 2008 @ 10:35 pm

  37. I want to route(send) the received message to any another person.But can not do.when I creates a new chat to send message to another ID it is not working…..can anybody help me.

    Thanx in advanced.

    Comment by Vijendra Yadav — November 13, 2008 @ 3:38 am

  38. Dear all,
    The link (smack, xmppclient.zip) you provided is somehow invalid. Could you please post it again?

    Thanks a lot.

    Comment by Canh cut — November 14, 2008 @ 3:37 am

  39. Hi all,
    i have a problem sending a message with PacketExtension.
    I successfully patched the smack sources with the given diff-file.
    It works fine, to send a Message to different clients. But if i add a PacketExtension, the message don’t arrive the recipient.
    I tested the same example with my patched sources as normal java application. This works fine.
    So i think there is maybe more to patch, that it works on android.

    Does anyone have the same problems and have a solution?

    Thanks.

    Comment by Bulldog — November 28, 2008 @ 4:06 am

  40. @Bulldog,
    how do you patch the diff file to Smack?
    thnx

    I am having trouble with changing security features of android and i am guessing that it has something to do with /system/etc/security/ stuff.
    anybody has any idea?

    thanks

    Comment by mike — November 29, 2008 @ 7:13 pm

  41. @mike,
    the patching is very easy – and i din’t use a diff-tool.
    Just download the sources, open it in eclipse. Then open the three files and apply the changes from the diff-file.
    Then download the kxml2.jar and place it in build/merge.
    Run ant and its done.
    With the security problems u mentioned i can’t help u.

    @All
    Whats about my problem with the PacketExtension???

    Comment by Bulldog — December 1, 2008 @ 2:50 am

  42. Hi all,
    Thanks in advance .please send me the link for XMPPClient.zip .

    Comment by Rajesh — December 10, 2008 @ 6:49 am

  43. Hello
    Give me AndroidMenifest.xml for XMPPClient By Dvanum shrinivas

    Regards
    Jagtap

    Comment by Jagtap — December 15, 2008 @ 4:55 am

  44. I want AndroidManifest.xml for XMPPClient , so if anybody have it forward me jagtap@igloo360.com

    Comment by jagtap — December 17, 2008 @ 5:00 am

  45. My android can’t authenticate to my XMPP server. however, I could use IM program to login to my server.

    The log in the server showed the sever had accepted the connection from android, but there was no any authentication occuring.

    please help me
    PS. I still don’t understand how to apply the patch.

    Thanks
    Addion

    Comment by Addion — December 18, 2008 @ 5:32 am

  46. Hi,

    The the code example and smack.jar are missing. Can someone please upload them?

    I went over the patch but no joy, unless I’m missing something there are still a lot missing pieces…

    Cheers,
    Ilan

    Comment by Ilan — December 19, 2008 @ 2:09 am

  47. Can anyone send me a link to download the patched smack.jar file?
    Thanks in advance.

    Comment by earlence — December 22, 2008 @ 1:42 am

  48. […] Android – Just use Smack API for XMPP « Show me the code! – By Davanum Srinivas […]

    Pingback by Updated XMPP Client for Android « Show me the code! - By Davanum Srinivas — December 29, 2008 @ 12:25 am

  49. hi…………
    what is xmpp?
    in simple sentence

    Comment by sujisha — March 9, 2009 @ 5:15 am

    • In general when we do chat,what happen we have to ping at server explicitly.But using we need not to ping explicit, it automatic reply when it have message for same conversion.

      Comment by shubham — July 30, 2010 @ 9:40 am

  50. how to add the smack.jar file。

    Comment by jacen — March 22, 2009 @ 9:04 pm

  51. thanks, it works well,

    Comment by Mahsa — March 31, 2009 @ 7:41 am

  52. using OpenFire server as well, so far everything is smoothly working. Now it’s time to extend this bad boy! 🙂

    Thanks again.

    Comment by Logor — April 22, 2009 @ 11:46 pm

  53. I tried same program but I am getting exception ” XMMPClient is not responding ”

    please help me
    Thanks

    Comment by abhijit — September 18, 2009 @ 8:02 am

  54. Let me first thank u for an excellent blog on XMPP.

    Further, i’d a few queries on an XMPP bot implementation I’m having:

    I’m planning to host an XMPP bot to which users can ask a query and it shall respond accordingly. I don’t think it is a difficult task at all. But, problem comes when scalability has to be built in.

    Here, there can be thousands of users online, who shall be firing their queries and the bot should respond with minimum latency. What was i planning is to fork a new thread inside the packetlistener event handler so that the event handler returns after the new thread is created. Also, i was planning to implement multiple packetlisteners for the same connection.

    Request you to kindly share ur thoughts on this. Any help shall be appreciated. Awaiting ur reply.

    Comment by Denil — December 27, 2009 @ 3:40 pm

  55. hey guys, great beginner’s guide. no answers have been given to many of the questions – if anyone can answer them please do. this seems to be the most comprehensive beginner’s guide to using smack on android so far. I’ve got the problem of XMPPError when trying to connect to localhost (both in words and ip). I’ve been going round in circles for ages.. if anyone could help it would be great. Server works anywhere else – including making a new account with spark and connecting with normal java. in the android environment i can connect to gmail no probs but not to localhost. please help

    Comment by Kris — March 31, 2010 @ 4:01 am

  56. Source code not dowloadable … Please send it or give link again..

    Comment by Anand — March 31, 2010 @ 5:59 am

  57. Man!!!!!!!!! u r god……….. I’m a fresher… learning android… i was screwed up cause of this security issue…. your code really helped me out!!!!!!!!!!

    Comment by karthik — August 4, 2010 @ 4:49 am

  58. How to get the contacts staus by using smack apis ?

    Thanks in advance.

    Comment by Amol — August 6, 2010 @ 1:17 am

  59. could this code connect to the xmpp client like openfire?? if yes how do i do that?

    Comment by william — August 26, 2010 @ 7:49 am

  60. I tried the code but it fails in connection.connect . can you please shed some light on it.

    Thanks

    Comment by satya — September 20, 2010 @ 6:44 am

  61. Hi,
    i m new to chat application
    thanks..for this beneficial code..

    I have run this client application having two screens…but i fail to understatnd the entries to be filled in setup screen….

    kinldy guide me the further steps..

    if any server is required..then plz do explain the details…

    Plz help me to establish chatting between two devices..with different userIDs…

    Thanks..

    Comment by medma — December 7, 2010 @ 3:06 am

  62. hey please help me with the source code. this link is not working. if someone has a working code then please mail me.

    Comment by Amit Panchal — December 30, 2010 @ 1:16 pm

  63. Hi davanum!

    I have a big problem with MultiUserChat.

    MultiUserChat mChatRoom = new MultiUserChat(connection, “myroom@conference.dev.kunkun.vn”);

    Form form = null;
    try {
    mChatRoom.create(“usertest2”);
    form = mChatRoom.getConfigurationForm();
    } catch (XMPPException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    It can’t create room chat at line: mChatRoom.create(“usertest2”);

    LOG:
    05-12 17:44:36.868: ERROR/AndroidRuntime(839): Caused by: java.lang.ClassCastException: org.jivesoftware.smack.packet.DefaultPacketExtension
    05-12 17:44:36.868: ERROR/AndroidRuntime(839): at org.jivesoftware.smackx.muc.MultiUserChat.getMUCUserExtension(MultiUserChat.java:2000)
    05-12 17:44:36.868: ERROR/AndroidRuntime(839): at org.jivesoftware.smackx.muc.MultiUserChat.create(MultiUserChat.java:364)
    05-12 17:44:36.868: ERROR/AndroidRuntime(839): at org.apache.android.xmpp.FriendsList.setConnection(FriendsList.java:170)
    05-12 17:44:36.868: ERROR/AndroidRuntime(839): at org.apache.android.xmpp.FriendsList.onCreate(FriendsList.java:87)
    05-12 17:44:36.868: ERROR/AndroidRuntime(839): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    05-12 17:44:36.868: ERROR/AndroidRuntime(839): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)

    Can you solve this bug? Please help me! Thanks!

    Comment by hnb1988 — May 12, 2011 @ 5:45 am

  64. Hi, great article and really it is very beneficial for me to implement chat between two user’s within my android application.
    Now i want to send the file also with chat messaging, i tried so much on this side, but not getting any success. Any one can help me to implement file attachment feature also with the text messaging, as this article shows.

    Comment by sumeetguha — July 28, 2011 @ 2:01 am

  65. Any one got success to send file also with chating on with smack library.

    Comment by sumeetguha — August 5, 2011 @ 6:09 am

  66. can you please give us a tutorial for file transfer using asmack?

    Comment by Usman Khalid — August 25, 2011 @ 5:29 am

  67. hi. friends find source code from here

    Updated XMPP Client for Android

    Comment by Nirav Dangi — September 7, 2011 @ 6:04 am

  68. hi great work thank u so much…

    but i need to know how to search users starting with name “t”

    UserSearchmanager help that but i don’t know the code in android

    is any one know the code? pls send me

    Comment by sha — October 12, 2011 @ 12:27 am

  69. 10-12 17:03:31.654: ERROR/AndroidRuntime(321): java.lang.IllegalStateException: Not connected to server.

    how can i solve this?

    Comment by johnprudence — October 12, 2011 @ 12:53 pm

  70. […] i have tested the below tutorial Example of XMPP with google id login […]

    Pingback by How to implement XMPP to send push notifications | Software development support, software risk,bugs for bugs, risk analysis, — January 13, 2012 @ 7:01 pm

  71. hi all

    plz help me while i running this app getting following exception :

    03-22 18:44:00.141: ERROR/AndroidRuntime(591): java.lang.IllegalStateException: Not connected to server.
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:329)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:301)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:283)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at org.apache.android.xmpp.SettingsDialog.onClick(SettingsDialog.java:60)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.view.View.performClick(View.java:2485)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.view.View$PerformClick.run(View.java:9080)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.os.Handler.handleCallback(Handler.java:587)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.os.Handler.dispatchMessage(Handler.java:92)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.os.Looper.loop(Looper.java:123)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.app.ActivityThread.main(ActivityThread.java:3647)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at java.lang.reflect.Method.invokeNative(Native Method)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at java.lang.reflect.Method.invoke(Method.java:507)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at dalvik.system.NativeStart.main(Native Method)

    Comment by sampath — March 22, 2012 @ 8:34 am

  72. Can anyone help me plz..My connection is workingn fine with server..I get the messages from the other user..but when i send the message to users it shows me nullpointer exception on
    connection.sendPacket(msg);
    Can anyone know me what is the problem??

    Comment by kur — April 21, 2012 @ 2:32 am

    • u are getting null pointer exception because u are not specifying address of the user(in the recipient ) whom u want to send the message to.

      Comment by deepesh khare — October 31, 2012 @ 7:38 am

  73. Can you provide solution for file transfer through asmack?

    Comment by sarath — April 24, 2012 @ 5:36 am

  74. E/AndroidRuntime(426): java.lang.NoClassDefFoundError: org.jivesoftware.smack.ConnectionConfiguration

    when i do the setup and click ok ..this error shows up in logcat.

    Comment by Kruti — June 29, 2012 @ 1:20 am

  75. A round of applause for your article.Really looking forward to read more. Awesome.

    Comment by Alyssa Minnich — July 2, 2012 @ 4:11 am

  76. Hello Mr. Davanum Srinivas
    is there are concept of friend request like that, Actually I am compile your code but chat is not showing, only user message are displaying, I am install in two emulator and try to implement chat but only user’s message are shown, Could you please help me do this?

    Thanks to Davanum Srinivas

    Comment by Ashish — July 24, 2012 @ 12:57 am

  77. can anybody help me to implement logout functionality from chat connection?

    Comment by Nagarjuna — July 27, 2012 @ 12:18 am

  78. how to implement logout function?

    Comment by Nagarjuna — July 27, 2012 @ 12:20 am

    • the connection is automatically terminated when you close your app and thus signing you out.

      Comment by deepesh khare — October 31, 2012 @ 7:39 am

  79. can any one solve E/AndroidRuntime(426): java.lang.NoClassDefFoundError: org.jivesoftware.smack.ConnectionConfiguration

    when i do the setup and click ok ..this error shows up in logcat.

    Comment by Raj — November 1, 2012 @ 6:14 am

  80. hi,
    when i run the above application, after setup i am filling all the details like host,port,user id and pwd then pressing ok.
    it is showing force close..
    can any one tell me where the problem is.

    Thanks in advance

    Comment by suji — December 27, 2012 @ 1:41 am

  81. How to know friend’s status whether he/she online or not?

    Comment by Rahul Upadhyay — May 31, 2013 @ 6:21 am

  82. hi..

    this example work completely but i don’t know how to send image not a text message to another device in this example please give me some suggestion for this.

    Thanks

    Comment by kaushik — December 3, 2013 @ 6:46 am

  83. 03-22 18:44:00.141: ERROR/AndroidRuntime(591): java.lang.IllegalStateException: Not connected to server.
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:329)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:301)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:283)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at org.apache.android.xmpp.SettingsDialog.onClick(SettingsDialog.java:60)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.view.View.performClick(View.java:2485)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.view.View$PerformClick.run(View.java:9080)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.os.Handler.handleCallback(Handler.java:587)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.os.Handler.dispatchMessage(Handler.java:92)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.os.Looper.loop(Looper.java:123)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at android.app.ActivityThread.main(ActivityThread.java:3647)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at java.lang.reflect.Method.invokeNative(Native Method)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at java.lang.reflect.Method.invoke(Method.java:507)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    03-22 18:44:00.141: ERROR/AndroidRuntime(591): at dalvik.system.NativeStart.main(Native Method)

    what the solution please help.

    Comment by chinni — February 3, 2014 @ 12:44 am

  84. How to setPacketId while sending the Message?

    Comment by Akhilesh — February 19, 2014 @ 5:50 am

  85. What if i want to connect to my own server ? If i want to use this app in my phone and connect to Openfire server installed in my pc what would be the configuration for ConnectionConfiguration, what should be my host, port, service_name ?

    Comment by Hudolf — March 6, 2014 @ 9:05 am

  86. hiiii i want to send and receive file using smack library using xmpp seerver . antbody can help me please.
    this toturial is great and working perfect .
    thanks.

    Comment by imrankhan — May 17, 2014 @ 6:40 am

  87. 06-10 13:37:55.518: E/AndroidRuntime(1079): FATAL EXCEPTION: main
    06-10 13:37:55.518: E/AndroidRuntime(1079): android.os.NetworkOnMainThreadException
    06-10 13:37:55.518: E/AndroidRuntime(1079): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at java.net.InetAddress.getAllByName(InetAddress.java:214)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at org.jivesoftware.smack.proxy.DirectSocketFactory.createSocket(DirectSocketFactory.java:30)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at org.jivesoftware.smack.XMPPConnection.connectUsingConfiguration(XMPPConnection.java:540)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at org.jivesoftware.smack.XMPPConnection.connect(XMPPConnection.java:984)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at com.example.xmppclient.SettingsDialog.onClick(SettingsDialog.java:44)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at android.view.View.performClick(View.java:4204)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at android.view.View$PerformClick.run(View.java:17355)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at android.os.Handler.handleCallback(Handler.java:725)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at android.os.Handler.dispatchMessage(Handler.java:92)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at android.os.Looper.loop(Looper.java:137)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at android.app.ActivityThread.main(ActivityThread.java:5041)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at java.lang.reflect.Method.invokeNative(Native Method)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at java.lang.reflect.Method.invoke(Method.java:511)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    06-10 13:37:55.518: E/AndroidRuntime(1079): at dalvik.system.NativeStart.main(Native Method)
    06-10 13:38:00.029: I/Process(1079): Sending signal. PID: 1079 SIG: 9

    how could i resolve this error what actual error is this

    Comment by aliashiq — June 10, 2014 @ 8:41 am

  88. i am not able to send messages.
    i am receiving messages but sending is not working

    Comment by shoeb — July 17, 2014 @ 8:04 am

  89. Hi,
    Is there any example for video chat using jingle.

    Comment by Madhulatha — July 21, 2015 @ 1:39 am


RSS feed for comments on this post. TrackBack URI

Leave a reply to sha Cancel reply

Create a free website or blog at WordPress.com.