Show me the code! – By Davanum Srinivas

December 29, 2008

Updated XMPP Client for Android

Filed under: Uncategorized — Davanum Srinivas @ 12:09 am

Updated the sources to latest android version – Android 1.0 SDK, Release 2

Original article:
http://davanum.wordpress.com/2007/12/31/android-just-use-smack-api-for-xmpp/

Updated screen shots:
1
2

Download Source and APK from here – XMPPClient-2.zip

About these ads

83 Comments »

  1. [...] Updated XMPP Client for Android [...]

    Pingback by Android - Just use Smack API for XMPP « Show me the code! - By Davanum Srinivas — December 29, 2008 @ 12:11 am

  2. Any chance you could make a .apk available as well as a .zip so we can list your app on AndAppStore and allow Android users to download and install the app directly?

    Comment by Al Sutton — December 29, 2008 @ 3:56 am

  3. Very cool. Built on OS X after tweaking the ant script. I tested it in the emulator against an OpenFire server. Next I’ll try it on my G1. Thanks for this.

    Comment by Mark Griffin — December 29, 2008 @ 9:47 pm

  4. Since other people successfully built and ran this project, I am starting to think it is my setting. I kept seeing this error generated from Packet Reader in the log file:

    java.security.KeyStoreException: KeyStore jks implementation not found

    This origin is from Smack’s PacketReader and I read a post about installing the “cacerts” file as follows:

    String javaHome = System.getProperty(“java.home”);
    StringBuffer buffer = new StringBuffer();
    buffer.append(javaHome).append(File.separator).append(“lib”);
    buffer.append(File.separator).append(“security”);
    buffer.append(File.separator).append(“cacerts”);
    config.setTruststorePath(buffer.toString());
    config.setTruststoreType(“jks”);
    config.setTruststorePassword(“changeit”);

    This didn’t seem to solve the problem on Windows. Can anyone provide any ideas how to proceed? If you actually use a patched version of Smack, could you either send me one copy or point me to where I can get one? I am doing a chess game between devices and honestly I am not quite sure if this is the right way to go.

    Thanks a lot.

    Comment by Chunyen Liu — December 30, 2008 @ 9:50 am

  5. Chunyen, you may want to try the patch that was posted by peter here:

    http://blog.jayway.com/2008/11/21/give-back-my-xmpp-in-android/

    He does mention that it fixes the “especiallly the keystore problem on the device”

    Comment by Davanum Srinivas — December 30, 2008 @ 10:17 am

  6. Find interesting and usefull information

    Comment by Ashly — January 3, 2009 @ 2:58 pm

  7. I tried to use this app to connect to my own XMPP server, but I can’t. I don’t know why it couldn’t login. I could use another XMPP client program to login. this is the error

    E/SOCKETLOG( 499): add_recv_stats recv 0
    E/SOCKETLOG( 499): add_recv_stats recv 0
    I/XMPPClient( 499): [SettingsDialog] Connected to 192.168.0.44
    W/System.err( 499): stream:error (host-unknown)
    W/System.err( 499): at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:306)
    W/System.err( 499): at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:44)
    W/System.err( 499): at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:76)
    E/XMPPClient( 499): [SettingsDialog] Failed to log in as test@192.168.0.44
    E/XMPPClient( 499): No response from the server.

    Comment by Addion — January 4, 2009 @ 10:46 pm

    • Try to add in the android.manifest file and don’t forget to use the patched smack.jar..Its working fine for me

      Comment by satya — September 20, 2010 @ 11:03 pm

      • Try to add uses-permission android:name=”android.permission.INTERNET” (enclosing in the seperate ) in the android.manifest file and don’t forget to use the patched smack.jar..Its working fine for me

        Comment by satya — September 20, 2010 @ 11:05 pm

  8. I forgot to say thank-you to you. Indeed, Peter’s solution is what I was looking for. I compiled a patched version of Smack and started to paddle along with my chess software on Android.

    Comment by Chunyen Liu — January 8, 2009 @ 10:27 am

  9. Hi,
    I am very new to Android world. I have downloaded XMPPClient-2.zip, extracted it and opened it in Eclipse 3.4.1 (Ganymede). I see following compilation errors in file, XMPPClient.java

    ———-
    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;
    ———

    ***Can not be resolved***

    and in file SettingsDialog.java

    ——–
    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;
    ———
    ***Can not be resolved***

    I understand that I had to some how make eclipse to know find above classe but I do not how to do that.

    Could anyone help me out with this?

    Thanks
    Maddy

    Comment by Maddy — January 13, 2009 @ 12:44 pm

    • Hi,
      have you managed it? I try to do the same but since i am very new to it a few hints might be helpful.

      Thanks and best, floda

      Comment by floda — May 7, 2009 @ 1:22 pm

      • Just right click smack.jar then add to build path, everything should work after that.

        Comment by nard — September 30, 2011 @ 12:39 am

  10. Hi,

    Can anyone send me a patched smack.jar file that works with Android 1.0 SDK, please?

    I thank you in advance.

    Comment by Arjun — January 14, 2009 @ 11:48 am

  11. Hi All,

    I have dowloaded XMPPClient-2.zip file and I had build smack.jar file by taking Peter’s solution. I successfully build and run this application in Android emulator. After filling in all details in Setup (XMPP Settings) screen and pressing OK button causes application to close. The following error is displayed after pressing OK button,

    —–
    Sorry!
    The application XMPP Demo (Process org.apache.android.xmpp) has stopped unexpectedly. Please try again.
    —–
    it comes with Force Close button and pressing on this closes the application.

    Does anyone has any idea on this error?

    Thanks
    Arjun

    Comment by Arjun — January 15, 2009 @ 10:47 am

    • 我也遇到这个问题,是因为smack.jar没有导入正确位置

      Comment by donnie — May 21, 2010 @ 4:45 am

  12. Hi All,

    I could finally got it working my making the patch for smack 3.1.0. If anyone want the patched smack please contact me on malli_730@yahoo.com, will send you by email.

    Thanks
    Maddy

    Comment by Maddy — January 19, 2009 @ 5:27 am

  13. [...] phone! i want a real jabber client for the g1 phone (general xmpp, maybe off smack?, sexier than this. ) who wants to [...]

    Pingback by no longer a nokia fangirl « fabienne.us — February 6, 2009 @ 11:34 am

  14. nice work, ran right from eclipse 1st try.

    Comment by adrian — February 11, 2009 @ 3:53 pm

  15. How do you use the patch listed on

    http://blog.jayway.com/2008/11/21/give-back-my-xmpp-in-android/

    I’m hoping this will solve my problems as currently the app crashes when I try to log in.

    Comment by steve — February 23, 2009 @ 7:35 am

  16. Hi all,
    the PacketExtension, mentioned in the old thread, still don’t work.
    Does no1 have a solution for this problem?
    Greez,
    Bull

    Comment by Bulldog — February 27, 2009 @ 4:05 am

  17. hi guys,

    Does anyone implement file transfer feature? I have got any notification when the file comes in. But i can use JDK version smack api to achieve that. Do anyone know how to implement this feature use fixed smack.jar here? thank you

    Comment by langjie — March 3, 2009 @ 12:52 pm

  18. hi,
    The error is:
    The application XMPP Demo (Process org.apache.android.xmpp) has stopped unexpectedly. Please try again.
    —–
    it comes with Force Close button and pressing on this closes the application.

    I want to known
    which servers do you choose?gtalk or open fire
    Thanks.

    Comment by jacen — March 25, 2009 @ 2:51 am

  19. Hello, I use Smack java library to send Instant messenger as you explain here. It works on the emulator but not on the G1 phone. Do you know why ?
    Thank you for your help.

    Comment by hellscarz — April 29, 2009 @ 11:25 am

  20. Hello, I 34 vuse Smack java library to send Instant messenger as you explain here. It works on the emulator but not on the G1 phone. Do you know why ?
    Thank you for45 your help.

    Comment by dGologan — May 12, 2009 @ 3:43 am

  21. Hello, I 34 vuse Smack java library to send Instant messenger as you explain here. It works on the emulator but not rt dgh tdh on the G1 phone. Do you know why ?
    Thank you for45 your help.

    Comment by dGologan — May 12, 2009 @ 3:43 am

  22. hi,
    this XMPP Client doesn’t work on sdk 1.5..

    is there source of any xmpp client for sdk 1.5?

    Comment by -=MccAt=- — May 30, 2009 @ 12:17 pm

  23. Hi Davanum

    same question as -=MccAt=-

    Any answer??

    Thanks Ben

    Comment by Ben Pitman — June 9, 2009 @ 8:24 am

  24. Hi.

    For all of those who’ve got an exception at program start.
    Try to add permission to use internet to the AndroidManifest.xml file.

    Comment by lunatic — June 12, 2009 @ 8:29 am

  25. Hi, and again:

    Any news on XMPP and sdk 1.5?? :-(

    Comment by Christian — June 19, 2009 @ 9:24 am

  26. For those using an OpenFire server and getting the “stopped unexpectedly” error message on connect, try using the server’s IP address or hostname instead of “localhost” or “127.0.0.1”.

    Also, for those having issues with 1.5, make sure you’re using the included /XMPPClient-2/XMPP/lib/smack.jar libraries and not the latest Smack libraries, which will probably give you errors in certificate authentication.

    Comment by Dustin Ingram — June 19, 2009 @ 5:44 pm

    • Dear Dustin,

      Thanks for your XMPPXClient2. I have successfully using it in message transferring.

      In further,I am trying to transfer a file by my self. However, I’ve got the nullpointexception

      in FileTransferNegotiator.setServiceEnabled(connection,true);

      Do you have idea ? Or should I need the any path file for Smack.jar?

      Thanks in advance.

      Comment by skymedi Chen — June 29, 2009 @ 3:44 am

  27. Hi Davanum

    I have downloaded the source and can compile/run successfully on emulator/g1 with 1.5. It will be great if you can post which smack version you use and what changes you have made to it and how you have created the smack.jar file. I have downloaded the smack 3.1 and use the patch from jayway http://blog.jayway.com/2008/11/21/give-back-my-xmpp-in-android/ But there are still a few more errors needed to resolved. It would be great if you can post how you create the smack.jar file which is included in your source.

    Comment by Win — July 3, 2009 @ 11:24 am

  28. when I fill the parameters in dialog box (after clicking on setup button) as host name,port,service,userid & password as talk.google.com, 5222, gmail.com, my gmail id without & password respectively, after that when I click on OK button, after some time it displays “XMPPClient is not responding”, exception on emulator. I am using Android sdk 1.5
    Please help me.
    Thanks in advance.

    Comment by Abhijit — September 22, 2009 @ 6:36 am

  29. when I fill the parameters in dialog box (after clicking on setup button) as host name,port,service,userid & password as talk.google.com, 5222, gmail.com, my gmail id & password respectively, after that when I click on OK button, after some time it displays “XMPPClient is not responding”, exception on emulator. I am using Android sdk 1.5
    Please help me.
    Thanks in advance.

    Comment by Abhijit — September 22, 2009 @ 6:37 am

  30. I have successfully run XMPP-Client2 without any problem in my emulator, and use the latest SDK-1.6. However, since I have not an available GPhone, if anyone tell me, I wonder whether it doesnot work in real GPhone? Does anyone try it successfully in GPhone in same condition?

    Comment by fangnster — September 29, 2009 @ 10:38 pm

  31. wrap the ConnectionConfiguration /XMPPConnection instatiation inside the try/catch statement to avoid this code bombing if there’s no host found / or connection timeout.

    Declare these at top…
    private ConnectionConfiguration connConfig = null;
    private XMPPConnection connection;

    then inside the

    public void onClick(View v) {

    ….
    try {
    connConfig = new ConnectionConfiguration(host, Integer.parseInt(port), service);
    connection = new XMPPConnection(connConfig);
    connection.connect();
    Log.i(“XMPPClient”, “[SettingsDialog] Connected to ” + connection.getHost());
    } catch (XMPPException ex) {
    Log.e(“XMPPClient”, “[SettingsDialog] Failed to connect to ” + connection.getHost());
    Log.e(“XMPPClient”, ex.toString());
    xmppClient.setConnection(null);
    return;
    }

    thanks to all the hard work to openfire /spark developers.

    Comment by John D Pope — February 18, 2010 @ 1:51 am

  32. Is there anybody know why we need a handle to deal with the received msg? THX, hurry to know the answers

    Comment by DoLoop — March 18, 2010 @ 4:44 pm

  33. hey .. dis is gonna sound like a rly stupid question but.. my application connects successfully to gmail but not to a localhost opefire server. i get XMPPException connection refused – im using the right permissions and the patched smack library. in normal java the connectio nis successful.. please .. any help ?:|

    Comment by Kris — March 31, 2010 @ 5:29 am

  34. hey,I am working with the project now,and I download your source but when I run it.there appears so many errors .I hope you can tell me your enviroment and how you generate your .APK file.THANK YOU

    Comment by lowen — May 8, 2010 @ 4:14 am

    • I have compiled successfully in android 1.5 and 1.6, but need to download ‘smack’ (maybe spelling has some error) API from internet, because xmpp function have been changed from 1.2 early version to 1.5 later version.

      good luck.

      Comment by fang ning — May 13, 2010 @ 11:14 pm

  35. I have compiled successfully in android 1.5 and 1.6, but need to download smack API from internet, because xmpp function have been changed from 1.2 early version to 1.5 later version.

    good luck.

    Comment by fang ning — May 13, 2010 @ 11:12 pm

  36. how to import this file to your android project ???
    may someone show me step by step import the file to android ?
    thnx

    Comment by sepat — June 25, 2010 @ 12:25 pm

  37. Hai ,
    every thing is fine in that application but in that they have included some extra files XmppClient.iml ,*.ipr,*.iws.Are these are mandatory for for running the application? if mandatory what is the use of those files where we have used in our application.please anybody clarify my doubt

    Thanks,
    Madhusudhan

    Comment by madhusudhan — July 7, 2010 @ 2:24 am

  38. I want to send images through the chat client, how can i achieve that with SMACK API in android ?

    Comment by Satyaban — August 18, 2010 @ 6:25 am

  39. I have dowloaded XMPPClient-2.zip file and I had build smack.jar file by taking . I successfully build and run this application in Android emulator. After filling in all details in Setup (XMPP Settings) screen and pressing OK button causes application to close. The following error is displayed after pressing OK button,

    —–
    Sorry!
    The application XMPP Demo (Process org.apache.android.xmpp) has stopped unexpectedly. Please try again.
    —–
    it comes with Force Close button and pressing on this closes the application.

    Does anyone has any idea on this error?

    Thanks
    please help me assp

    Comment by Renuka — August 19, 2010 @ 6:03 am

  40. hi there, when i ran the program the logcat said that i can’t connect to talk.google.com. Are there other ways to connect to this service? I ran it using android 2.2 and already using the patched smack.

    Comment by dominick — August 30, 2010 @ 5:09 am

  41. SASLAuthentication.supportSASLMechanism(“PLAIN”, 0); is not working with patched smack.jar . Anyone has any idea??

    Comment by satya — September 29, 2010 @ 4:13 am

  42. Fine app for android thanks for the tip I am already experimenting in my android and perfect
    a work in very nice.

    Comment by Android — January 4, 2011 @ 9:50 pm

  43. This article helped me a lot. Thank you

    Comment by Start — May 8, 2011 @ 10:12 pm

  44. Thank you very much!!! It works perfect with openfire server.

    Comment by Marta — May 20, 2011 @ 3:40 am

  45. Very Very Usefull code…………….

    Comment by Nandlal — May 30, 2011 @ 4:50 am

  46. Hi

    This app is working for GTalk for me.. I am trying to connect with “chat.facebook.com”.. but getting exception while making connection. “No response from server”

    Please let me know how I could connect with facebook chat.. what I need to implement here

    Thanks
    Aparna

    Comment by aparna — June 9, 2011 @ 7:34 am

    • Samething for me too… AnyLuck on the Facebook

      Comment by srinath — October 8, 2011 @ 11:35 am

  47. Hi, I have a small problem. I am using the code, the compilation works fine, I am able to run the application bun when I try to connect to my local server (127.0.0.1:5222) a problem appears.
    Here it is the log:

    06-16 14:46:25.764: ERROR/XMPPClient(879): [SettingsDialog] Failed to connect to 127.0.0.1
    06-16 14:46:25.774: ERROR/XMPPClient(879): XMPPError connecting to 127.0.0.1:5222.: remote-server-error(502) XMPPError connecting to 127.0.0.1:5222.
    06-16 14:46:25.774: ERROR/XMPPClient(879): — caused by: java.net.ConnectException: /127.0.0.1:5222 – Connection refused

    The problem might appear because I probably didn’t configure my XMPP server correctly. I installed OpenFire on my computer and created an account other the admin. I believe I must add some other stuff to my server?:-s
    I am very new in the client-service configuration.

    Thank you.

    Comment by scutu — June 16, 2011 @ 10:03 am

  48. Can we do group chat and file sharing in gtalk through this xmpp concept?

    Comment by PJ — November 23, 2011 @ 1:23 am

  49. could somebody please upload their .apk file?

    Comment by Moish — January 25, 2012 @ 6:15 pm

  50. [...] which I can chat to gtalk,facebook,skype,Yahoo messenger etc.I am using the code from Updated XMPP Client for Android Show me the code! – By Davanum Srinivas but my exact requirements are not met in this. [...]

    Pingback by XMPP/Jabber Application - Android Forums — February 9, 2012 @ 9:53 am

  51. Any idea about video chat using XMPP and smackx jingle API in Android.
    I can not able to find good Sample code to start.

    Comment by Android Buddy — March 3, 2012 @ 5:46 am

  52. i have downloaded the source code and run the project. project runs successfully but messages are not sent.
    first i have tried on localhost using openfire then i tried using gmail account.

    Comment by juned — April 11, 2012 @ 7:15 am

  53. Group chat is not supported in this.Could you please give me an example like the same on group chatting(MUC).

    Comment by john — May 21, 2012 @ 8:49 am

  54. This code dose not run on emulator , It got forced close with exception ” java.lang.NoClassDefFoundError: org.jivesoftware.smack.ConnectionConfiguration ” . Please help me. what should I do to run the code. I am also include the smack.jar file from lib folder

    Comment by Chetan Bhoyar — May 22, 2012 @ 5:21 am

    • Is there any smack api for android which support xmpp connection and all , In the given code samck api is there but it doesn’t work for me as I am trying it for several time with different smack apis , facing same problem . . please help me.

      Comment by Chetan Bhoyar — May 24, 2012 @ 6:54 am

  55. Hello…
    i want to get online friend list .
    i am trying but its not working good .
    have you any idea?

    Comment by yogesh — May 23, 2012 @ 3:52 am

  56. [...] am using XMPP example from this address. I am putting the following configuration in setup for XMMP [...]

    Pingback by XMPP client cannot connect to gtalk server in Android | PHP Developer Resource — May 24, 2012 @ 8:09 pm

  57. thanks to give a good start,
    I am trying to implement your code but, chat is not showing, In chat list, there are user send messages displayed, How to implement chat properly,

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

  58. Hi,

    If your code is givingn an error about android.os.NetworkOnMainThreadException you need to do the connection.connect() in a asynctask. In newer versions of android it’s not permitted to use the main thread for connection. This stackoverflow issue gives an good example: http://stackoverflow.com/questions/11756432/connect-to-google-talk-using-smack

    Comment by Mvk — October 12, 2012 @ 9:10 am

  59. thanks

    Comment by suji — January 7, 2013 @ 8:24 am

  60. application when click on setting screen ok button ……Error is 05-09 12:09:52.570: E/AndroidRuntime(27146): java.lang.NoClassDefFoundError: org.jivesoftware.smack.ConnectionConfiguration ………i already build path of smack jar file …..please help me thank you

    Comment by Hiren — May 9, 2013 @ 1:43 am

  61. hi …file transfer is possible for this xmpp client source code??

    Comment by Hiren — May 9, 2013 @ 5:47 am

  62. its very good but how to test it in windows pc

    Comment by manoj karki — June 10, 2013 @ 12:06 pm

  63. […] I try to implement chat support as suggested in this blog. […]

    Pingback by Integrate Facebook chat in android with Asmack API - Tech Forum Network — June 12, 2013 @ 3:18 pm

  64. […] been using the patched Smack library from here as is suggested in many other questions here in SO. However, that’s a patched version of the […]

    Pingback by Android and XMPP: Currently available solutions | BlogoSfera — August 2, 2013 @ 7:02 pm

  65. Hi Davanum. I was able to execute you sample successfully. But when i try to login to a jabber id or any other chat id it is not connecting and it is raising exception. Plz help me

    Comment by KK — August 22, 2013 @ 8:17 am

  66. how to read chat history using xmpp in androiid.

    Comment by Jignesh — October 25, 2013 @ 6:13 am

  67. […] been using the patched Smack library from here as is suggested in many other questions here in SO. However, that’s a patched version of the […]

    Pingback by Android and XMPP: Currently available solutions | Ask Programming & Technology — November 4, 2013 @ 6:33 pm

  68. what should I pass in the Host and in Services ? I am using openfire xmpp server??

    Comment by gulshan — November 8, 2013 @ 8:23 am

  69. hey any one knows using XAMPP how to connect to the yahoo messenger

    Comment by Maheshwar — April 27, 2014 @ 12:53 am

  70. Thanks. I used your code and creating an android app and adding new stuff to it. I hosted the complete source code on GitHub here https://github.com/gudigundla/AndroidXMPPClient Feel free to fork it and send pull requests. Here’s the blog post on how to use it with local XMPP server http://im-a-developer-too.blogspot.ca/2014/04/creating-android-xmpp-client-using.html. You may install it on your android device freely from here https://play.google.com/store/apps/details?id=org.apache.android.xmppClient

    Comment by Hari Gudigundla — April 29, 2014 @ 8:07 pm

  71. What would i do if i wanted to connect to a server that’s using BOSH?

    Comment by AEaddict — June 26, 2014 @ 11:56 am


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 133 other followers

%d bloggers like this: