I am trying to make one of this simple example:
SSH, execute remote commands with Android
I just want to see if I can connect from my Android phone to the linux server using SSH, but it does not work ...
Here is my main code:
package com.example.ssh;
import java.util.Properties;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import android.os.Bundle;
import android.app.Activity;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try
{
JSch jsch = new JSch();
Session session = jsch.getSession("root","192.168.0.26", 22);
session.setPassword("xxxxx");
Properties prop = new Properties();
prop.put("StrictHostKeyChecking", "no");
session.setConfig(prop);
session.connect();
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
}
}
What did I do wrong? I have no error messages and I do not see any SSH connection on my Linux. I added jsch and jzlib libraries. I have no problem connecting to the putty session.
EDIT1: Actually, I found an error explaining why it does not work, even if I do not know how to solve the problem. Error:
android.os.NetworkOnMainThreadException
so this means that the application cannot perform a network operation in its main thread ...