I\'m learning Android programming and I\'ve been trying to figure this out for a couple days now. I\'m writing and Android app that is supposed to connect to XMPP server. I\'m g
I had the same problem, but found solution here: SImple Asmack program not working
The solution is to put connection code into separate thread.
public static final String HOST = "208.68.163.218"; //write your host name
public static final int PORT = 5222;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
connect();
}
public void connect() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
Context context = getApplicationContext();
SmackAndroid.init(context);
ConnectionConfiguration ConnectionConfiguration = new ConnectionConfiguration(HOST, PORT);
ConnectionConfiguration.setDebuggerEnabled(true);
XMPPConnection connection = new XMPPTCPConnection(ConnectionConfiguration);
try {
connection.connect();
} catch (ConnectionException e) {
e.printStackTrace();
} catch (SmackException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XMPPException e) {
e.printStackTrace();
}
}
});
t.start();
}