How to delete folders from SDCard during uninstall

2019-02-23 05:58发布

I went through the following link which says that the external folders will be deleted automatically during uninstallation of my app.

I am using the following code to create the folders and file:

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

My problem is that the folder myAppFolder is not getting deleted when I uninstall the app.

Am I going wrong anywhere?

4条回答
干净又极端
2楼-- · 2019-02-23 06:28

No. The Android OS does not remove the SDCard files corresponding to one App when the App is uninstalled.

查看更多
劫难
3楼-- · 2019-02-23 06:39

Save it in your Apps Private Folder (/data/data/yourappPackege). This folder will be removed when uninstalling the App.
You can get your private Folder with the Method getFilesDir() Other files can not be removed because your App does not "know" when it is being removed.

查看更多
戒情不戒烟
4楼-- · 2019-02-23 06:40

see this work for delete

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

}

查看更多
Rolldiameter
5楼-- · 2019-02-23 06:42

Hey the link says that If you use getExternalCacheDir(), then only folders auto deleted when uninstalling the app. So please correct your self. If you are using getExternalStorageDirectory , then you have to manually delete the folder by programming

to delete a folder you can use below code

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

    File f1=new File(TEMP_FOLDER_PATH);
    f1.delete();
查看更多
登录 后发表回答