I'm using the JSCH library to connect my phone to my desktop via SSH and run command line arguments on my desktop from my phone. Here is the method I'm using to communicate with the JSCH library and run the command:
I pulled that off another website tutorial and never modified it. I call that method with the proper parameters and it works perfect except for one thing......I need to run the following commands prior to calling the method:
Without those I get an error which references the fact you shouldn't run network commands from the main UI or something similar. Can anyone tell me how I can run this without the policy changes? Thanks!
Code:
public static String executeRemoteCommand(
String username,
String password,
String hostname,
int port,
String command) throws Exception {
JSch jsch = new JSch();
Session session = jsch.getSession(username, hostname, 22);
session.setPassword(password);
// Avoid asking for key confirmation
Properties prop = new Properties();
prop.put("StrictHostKeyChecking", "no");
session.setConfig(prop);
session.connect();
// SSH Channel
ChannelExec channelssh = (ChannelExec)session.openChannel("exec");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
channelssh.setOutputStream(baos);
// Execute command
channelssh.setCommand(command);
channelssh.connect();
channelssh.disconnect();
return baos.toString();
}
I pulled that off another website tutorial and never modified it. I call that method with the proper parameters and it works perfect except for one thing......I need to run the following commands prior to calling the method:
Code:
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Without those I get an error which references the fact you shouldn't run network commands from the main UI or something similar. Can anyone tell me how I can run this without the policy changes? Thanks!