开发者

How to delete entire contents of sdcard programmatically in Android 2.2

I wish to delete the users entire SDcard programmatically in Android 2.2.开发者_如何学Go

  1. What is the easiest way to do this?

  2. Will it require root rights?

  3. Can I just do an "rm -rf /mnt/sdcard" or do I have to make a recursive loop?


  1. You can delete directories with Java. You have to do it recursively if they are not empty: http://www.exampledepot.com/egs/java.io/DeleteDir.html

  2. No. All applications have full RW access to external storage.

  3. Yes you can execute shell commands (but you'll have to check if "rm" is available): Any way to run shell commands on android programmatically?

Checking for available commands: How can I get information from the shell about commands available in Android shell?


Don't run shell commands, they are not part of the SDK. There is a good chance your app will break on some devices that don't have whatever shell command you are running. It is easy to use the Java file APIs to iterate through all files and delete them.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜