我是Android和Java的新手,这是我的情况:
我正在尝试使用ssh连接创建连接到Beaglebone Black的应用程序,然后通过发出来自Android设备的命令来控制连接到BBB的一些外围设备.我在AsyncTask中打开(成功)ssh会话,同时用户看到启动画面,如果连接成功,用户将获得确认,然后可以通过单击一些可用按钮发送预定义命令.
我接下来要做的是让会话打开,然后每次我想发出命令并等待BBB的响应时创建一个新的通道(exec或shell),但我不知道如何重用这样的ssh AsynkTask之外的会话.
甚至可能吗?
我使用的是Android Studio 0.8.2和Jsch 0.1.51,我的代码如下:
公共类SplashScreen扩展ActionBarActivity {
public static final int segundos =10;
public static final int milisegundos =segundos*1000;
public static final int delay=2;
private ProgressBar pbprogreso;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
pbprogreso= (ProgressBar)findViewById(R.id.pbprogreso);
pbprogreso.setMax(maximo_progreso());
empezaranimacion();
}
public void empezaranimacion()
{
sshConnect task = new sshConnect();
task.execute(new String[] {"http:"});
new CountDownTimer(milisegundos,1000)
{
@Override
public void onTick(long milisUntilFinished){
pbprogreso.setProgress(establecer_progreso(milisUntilFinished));
}
@Override
public void onFinish(){
finish();
}
}.start();
}
public int establecer_progreso (long miliseconds) …Run Code Online (Sandbox Code Playgroud)