How to delete folders from sdcard while uninstalling my android application?

I looked at the following link which says that external folders will be deleted automatically when my application is deleted.

I use the following code to create folders and file:

private static String TEMP_FOLDER_PATH = Environment.getExternalStorageDirectory() + "/myAppFolder/";

My problem is that the myAppFolder folder is not deleted when the application is deleted.

Am I mistaken?

+5
source share
4 answers

Save it in the Apps private folder (/ data / data / yourappPackege). This folder will be deleted when the application is uninstalled.
You can get your private folder using the method getFilesDir() Other files cannot be deleted, because your application does not "know" when it is deleted.

+10

, , getExternalCacheDir(), . , , . getExternalStorageDirectory, ,

,

TEMP_FOLDER_PATH = Environment.getExternalStorageDirectory() + "/myAppFolder/";

    File f1=new File(TEMP_FOLDER_PATH);
    f1.delete();
+1

. Android SDCard, , .

0

.

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

}

-1

All Articles