android代码中运行二进制程序或脚本
android 代码中运行二进制程序或脚本
#移动开发 #Android
1. 知识点
在程序中执行 shell 脚本或程序(线程中执行),并显示进度条
2. 示例
功能
实现在程序中运行命令”sleep 3”,在线程中进行,并显示进度条代码
_ ……
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();
} _
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.