开发者

How to execute a system command from an android application

I would like to know how to execute a system command开发者_C百科 from an android application?

For example :

I would like to create a directory while I am running an application, so i need to execute the command "mkdir -p /x/y".

Please guide me with valuable pointers.

Thanks,

Sen


TO create a directory(for example on sd-card) you should use the other way:

File  file = new File(Environment.getExternalStorage() + "/folder-name");
file.mkdirs();

To write to external storage you should have the following permission in your manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

To execute a system command usually used Runtime.getRuntime().exec("ls -l");


Sen,

I believe you are trying to run shell commands from an android app similar to an aandroid terminal app.Right? This link might be helpful.

Note:The post contains certain ways to drop a shell command from an app(do check those links in the post)


I think Vladimir Ivanov means:

File file = new File(Environment.getExternalStorageDirectory() + "/folder-name");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜