Delete a folder on SD card

Solution 1:

You have to have all the directory empty before deleting the directory itself, see here

In Android, you should have the proper permissions as well - WRITE_EXTERNAL_STORAGE in your manifest.

EDIT: for convenience I copied the code here, but it is still from the link above

public static boolean deleteDirectory(File path) {
    if( path.exists() ) {
      File[] files = path.listFiles();
      if (files == null) {
          return true;
      }
      for(int i=0; i<files.length; i++) {
         if(files[i].isDirectory()) {
           deleteDirectory(files[i]);
         }
         else {
           files[i].delete();
         }
      }
    }
    return( path.delete() );
  }

Solution 2:

https://stackoverflow.com/a/16411911/2397275

uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"

in AndroidManifest.xml file