在Android开发中,我们如何通过编码消灭整个SD卡?我需要通过我的应用程序格式化SD卡内容。
答案 0 :(得分:2)
我找到了答案, 只需调用wipeMemoryCard();
public void wipeMemoryCard() {
try {
File deleteMatchingFile = new File(Environment.getExternalStorageDirectory().toString());
File[] filenames = deleteMatchingFile.listFiles();
if (filenames != null && filenames.length > 0) {
for (File tempFile : filenames) {
if (tempFile.isDirectory()) {
wipeDirectory(tempFile.toString());
} else {
tempFile.delete()
}
}
}
} catch (Exception e) {
}
}
private void wipeDirectory(String name) {
try {
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());
} else {
tempFile.delete()
}
}
}
} catch (Exception e) {
}
}