hardik kubavat

Android client using Smack-4.1.0 Api Backend Openfire

Discussion created by hardik kubavat on May 12, 2015
Latest reply on Jun 8, 2015 by Yan Sheng Neng

I am new to use Openfire..
I have successfully configure openfire in my localhost

 

*From this link  : http://code.tutsplus.com/articles/create-a-flexible-xmpp-chat-for-a-member-based -website-with-flash-and-php--active-9858

and i have tested it using Spark ... it's work fine

 

now i am moving to build chat Application in Android ...

 

as per some blogs , igniterealtime community or stackoverflow i have follow below steps to Develope Android Application...

 

Step 1 : Integrating Smack-4.1.0 Api in Android project

*(personally i use Eclipse and latest Android SDK)

 

    import below  jars in android project

 

     jxmpp-core-0.4.0.jar

     jxmpp-util-cache-0.4.0.jar

     minidns-0.1.1.jar

     smack-android-4.1.0.jar

     smack-android-extensions-4.1.0.jar

     smack-core-4.1.0.jar

     smack-extensions-4.1.0.jar

     smack-im-4.1.0.jar

     smack-sasl-provided-4.1.0.jar

     smack-tcp-4.1.0.jar

 

* i got this jar from this link  Maven Repository: org.igniterealtime.smack

 

Step 2 : write a code for Android client

 

here is my code :

 

import org.jivesoftware.smack.AbstractXMPPConnection;

import org.jivesoftware.smack.SmackException;

import org.jivesoftware.smack.XMPPException;

import org.jivesoftware.smack.tcp.XMPPTCPConnection;

import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;

 

 

public class TestActivity extends Activity {

 

  public String HOST = "192.168.xx.xx"; // as per your server

 

  public String UserName = "user2";

  public String Password = "pass2";

  public int PORT = 5222;

 

  public static String TAG = "Test connection" ;

 

@Override

protected void onCreate(Bundle savedInstanceState)

{

       super.onCreate(savedInstanceState);

       setContentView(R.layout.login_screen);

 

       btn_login.setOnClickListener(new OnClickListener()

      {

            @Override

            public void onClick(View v)

            {

                    connect();

            }

       });

 

 

}

}

 

public void connect()

{

     AsyncTask<Void, Void, Void> connectionThread = new AsyncTask<Void, Void, Void>()

     {

          @Override

           protected Void doInBackground(Void... arg0)

           {

                  // Create the configuration for this new connection

                   XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();

 

                   configBuilder.setUsernameAndPassword(UserName + "@"+ HOST, Password);

                   configBuilder.setSecurityMode(XMPPTCPConnectionConfiguration.SecurityMode.disab led);

                   configBuilder.setServiceName(HOST);

                   configBuilder.setPort(PORT);

                   configBuilder.setHost(HOST);

                   configBuilder.setDebuggerEnabled(true);

  

                   AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());

 

 

                   connection = new XMPPTCPConnection(configBuilder.build());

                   connection.setPacketReplyTimeout(10000);

 

 

                try

                {

                     connection.connect();

                     connection.login();

                }

               catch (SmackException | IOException | XMPPException e)

                {

                    Log.d("AsyncTask", e.toString());

                }

 

                return null;

            }

 

 

        };

        connectionThread.execute();

    }

}

 

*when i run this i got following error

 

     java.lang.NoSuchMethodError: org.jxmpp.util.XmppStringUtils.completeJidFrom

     at org.jivesoftware.smack.tcp.XMPPTCPConnection.openStream(XMPPTCPConnection.java: 925)

     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.writePackets(XMPPTCPC onnection.java:1299)

     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter.access$2700(XMPPTCPCo nnection.java:1166)

     at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketWriter$1.run(XMPPTCPConnecti on.java:1214)

     at java.lang.Thread.run(Thread.java:841)

 

 

can anyone tell me where i am wrong or anything that i missed ...?

 

any kind of help would be greatly appreciated ... !

 

Outcomes