How to delete folders from SDCard during uninstalling of my app in Android?

喜你入骨 提交于 2019-12-01 18:00:34

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.

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

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

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

}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!