Before doing this app Download ASmack Library and Enable Internet permission in you manifiest.
public class ASmackAsync extends AsyncTask<String, Void, String>{
private ProgressDialog pd;
private Context ctxt;
public ASmackAsync(Context ctxt) {
this.ctxt=ctxt;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pd=new ProgressDialog(ctxt);
pd.show();
pd.setContentView(new ProgressBar(ctxt), new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
}
@Override
protected String doInBackground(String... params) {
return ASmack.connectGServer(params[0], params[1]);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
pd.dismiss();
if(result==ASmack.GCONNECT){
Toast.makeText(ctxt, "Connected",10).show();
}else{
Toast.makeText(ctxt, result,10).show();
}
}
}
public class ASmack {
public static String GCONNECT="GCONNECTED";
public static XMPPConnection gconn;
public static String connectGServer(String user,String pass){
String host="talk.google.com";
int port=5222;
String service="gmail.com";
ConnectionConfiguration config=new ConnectionConfiguration(host,port,service);
gconn=new XMPPConnection(config);
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
config.setDebuggerEnabled(true);
try {
gconn.connect();
Log.i("Host", gconn.getHost());
gconn.login(user, pass);
} catch (XMPPException e) {
e.printStackTrace();
}
return GCONNECT;
}
}