【发布时间】:2011-02-06 23:19:49
【问题描述】:
在我的应用程序中,我想在运行时从我的应用程序在 sdcard 中创建一个目录 xyz。
但它不起作用。
这是我的代码..
public class process extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String[] str ={"mkdir","/sdcard/xyz"};
try {
Process ps = Runtime.getRuntime().exec(str);
try {
ps.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (IOException e) {
Toast.makeText(this, ""+e, Toast.LENGTH_LONG).show();
}
}
}
【问题讨论】:
-
您不能从应用程序运行 adb shell 命令,因为 adb shell 是通过 adb 守护程序获得的 shell。目前,您可以作为应用程序用户运行通用 shell 命令,但官方不鼓励这样做。考虑这样做的理由相对较少,在您的申请过程中可以轻松完成的事情绝对不是其中之一。
标签: android shell command execute adb