如何在root用户的棒棒糖中擦拭SD卡?

时间:2016-02-13 14:11:27

标签: android android-sdcard

如何在android rooted lolliop中永久擦除SD卡。我使用过这个链接( stackoverflow.com/questions/13737327/android-wipe-out-sd-card-programatically),但不适合我。

2 个答案:

答案 0 :(得分:0)

试试这个:

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();
    }
}

答案 1 :(得分:0)

ExternalStorageFormatter类负责格式化存储设备。但它没有暴露给3P应用程序。

http://androidxref.com/5.1.1_r6/xref/frameworks/base/core/java/com/android/internal/os/storage/ExternalStorageFormatter.java

浏览该类中的方法,看看是否可以使用任何反射技术来触发该类的格式化。