1. 知识点
在程序中执行shell脚本或程序(线程中执行),并显示进度条
2. 示例
a) 功能
实现在程序中运行命令”sleep 3”,在线程中进行,并显示进度条
b) 代码
……
String commands = "sleep 3";
sendshell(commands);
……
public void sendshell(final String commands) {
String mymsg = "run " + commands;
patience = ProgressDialog.show(this, "please wait", mymsg, true);
Thread t = new Thread() {
public void run() {
try {
Process process = Runtime.getRuntime().exec(commands);
process.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
patience.dismiss();
}
};
t.start();
}