Android client using Smack-4.1.0 Api Backend Openfire

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 … ! **

I was wrong at Import Jars and also sequence of steps to established connection with openfire …

**Solution of my problems i have imported below jars in my projects …

importjars.PNG

**working Code for Connection


private class ConnectToXmpp extends AsyncTask<Void, Void, Void> {

@Override

protected void onPreExecute() {

super.onPreExecute();

}

@Override

protected Void doInBackground(Void… params) {

// Create the configuration for this new connection

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();


** configBuilder.setSecurityMode(XMPPTCPConnectionConfiguration.SecurityMode.disabled);**

** // configBuilder.setResource(“testServices”);**

** configBuilder.setServiceName(SERVICENAME);**

** configBuilder.setHost(HOST);**

** configBuilder.setPort(PORT);**

** configBuilder.setCompressionEnabled(false);**

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

/** Connecting to the server */

try {

connection.connect();

Log.i(TAG, "Connected to " + connection.getHost());

} catch (SmackException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

} catch (XMPPException e) {

Log.e(TAG, "Failed to connect to " + connection.getHost());

Log.e(TAG, e.toString());

e.printStackTrace();

}

/** LogingIn to the server */

try {

connection.login(UserName, Password);

Log.i(TAG, "Login as a : " + connection.getUser());

} catch (XMPPException e) {

e.printStackTrace();

Log.i(TAG, "Login error " + e.toString());

} catch (SmackException e) {

e.printStackTrace();

Log.i(TAG, "Login error " + e.toString());

} catch (IOException e) {

e.printStackTrace();

Log.i(TAG, "Login error " + e.toString());

}

return null;

}

@Override

protected void onPostExecute(Void result) {

}

}

**that’s it… !! **

In Above code Connection is Successfully established… !!

**but Login is still not working … **

__**it’s throw below error message __

**Login error org.jivesoftware.smack.SmackException: SASL Authentication failed. No known authentication mechanisims.

__**Now i m finding a solution for Register a new user to my Openfire server __

**i need a solution for login or register a new user … **

any kind of help would be greatly appreciated … !

Can you used openfire now?

I used your code any libs, is ok

you maybe forget the server name :

public String SERVER_NAME = “ubuntu”;//add this server name

// Create the configuration for this new connection

XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();

configBuilder.setUsernameAndPassword(UserName + “@”+ SERVER_NAME, Password);

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

configBuilder.setServiceName(SERVER_NAME);

configBuilder.setPort(PORT);

configBuilder.setHost(HOST);

configBuilder.setDebuggerEnabled(true);

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

QQ图片20150608180550.png

I’m chinese .English so bad.wish you understadn!

and thank you very much