How can I programmatically delete data or format the entire SD Card?
code to wipe SDCARD
public void wipingSdcard() {
File deleteMatchingFile = new File(Environment
.getExternalStorageDirectory().toString());
try {
File[] filenames = deleteMatchingFile.listFiles();
if (filenames != null && filenames.length > 0) {
for (File tempFile : filenames) {
if (tempFile.isDirectory()) {
wipeDirectory(tempFile.toString());
tempFile.delete();
} else {
tempFile.delete();
}
}
} else {
deleteMatchingFile.delete();
}
} catch (Exception e) {
e.printStackTrace();
}
}
private void wipeDirectory(String name) {
File directoryFile = new File(name);
File[] filenames = directoryFile.listFiles();
if (filenames != null && filenames.length > 0) {
for (File tempFile : filenames) {
if (tempFile.isDirectory()) {
wipeDirectory(tempFile.toString());
tempFile.delete();
} else {
tempFile.delete();
}
}
} else {
directoryFile.delete();
}
}
BadSkillz
Try reading up on this one How to delete a file from SD card?
By using the File class you should be able to list all the files on the SDCard and to delete each of them one by one. You'll make a recursive function to delete directories. It is however not such a good idea and the OS might prevent you from deleting some of the files/folders used by the system or another user.
来源:https://stackoverflow.com/questions/4749891/how-can-i-programmatically-format-all-data-on-an-sd-card