我正在做一个简单的应用程序,像shell一样显示android中的当前进程。
我的应用程序执行ls、cd、makedir和其他命令,但top或htop命令不执行。(htop无法识别应用程序冻结)。我需要根吗?我已经下载了终端应用程序在未推出的android和顶部命令工作。
我的应用程序有2个类。一个本金和一个空壳
主类
public void onClick(View arg0) {
// TODO Auto-generated method stub
ShellExecuter exe = new ShellExecuter();
command = input.getText().toString();
String outp = exe.Executer(command);
out.setText(outp);
Log.d("Output", outp);
}
外壳级
public String Executer(String command) {
StringBuffer output = new StringBuffer();
Process p;
try {
p = Runtime.getRuntime().exec(command);
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = reader.readLine())!= null) {
output.append(line + "n");
}
} catch (Exception e) {
e.printStackTrace();
}
String response = output.toString();
return response;
}
为什么应用程序的某些命令有效,而top则无效??
如果您已连接设备,请转到shell,使用计算机命令行中的以下命令查看可用的命令:
adb外壳
乍一看,您将能够知道"top"是一个"显示和更新有关进程的排序信息"的作业,它会阻塞shell命令行,因此,在您的应用程序中锁定执行该命令的线程。
希望有帮助!
问候!
谢谢。带有顶部命令的adb shell显示进程
但是
p = Runtime.getRuntime().exec("top");
也许不管用??
我不理解,因为我的应用程序冻结
还是top-n 1没有固定?