我似乎无法在我的 Android 应用程序中运行 runtime.exec。我已经尝试使用许多 shell 实用程序,这是我正在使用的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
filesPrinter = (Button) findViewById(R.id.print_files);
filesPrinter.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
Process proc = Runtime.getRuntime().exec("ls");
out = new BufferedWriter(new OutputStreamWriter(proc.getOutputStream()));
in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
String line;
while((line = in.readLine()) != null) {
System.out.println(line);
}
System.out.println("Done reading");
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
我没有收到错误,但在 logcat 中也没有收到任何信息。
最佳答案
问题最终成为 eclipse logcat 的错误。使用 adb logcat,我可以看到应该输出的所有内容。出于某种原因,eclipse 上的 logcat 显示它已连接但未从模拟器接收任何应用程序级输出。
关于java - 无法在 android 上运行 runtime.exec,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11164237/