Theis Borg
Theis Borg

Reputation: 378

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.

  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?

Upvotes: 3

Views: 3677

Answers (2)

hackbod
hackbod

Reputation: 91341

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.

Upvotes: 2

Peter Knego
Peter Knego

Reputation: 80340

  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?

Upvotes: 2

Related Questions