0

I made an application from which I make a folder and save some files in it.

What I want is, when I delete the application the folder that I make outside from application should be deleted.

PEHLAJ
  • 9,980
  • 9
  • 41
  • 53
Ali Rehman
  • 13
  • 6
  • If you want your directory to be deleted on app uninstall then you should create it inside your cache directory. https://developer.android.com/reference/android/content/Context.html#getExternalCacheDir() – Muhammad Babar May 16 '17 at 05:42

2 Answers2

0

Add your manifest following permission

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

Then java code

File dir = getActivity().getFilesDir();
if (dir.isDirectory()) 
{
String[] subDir = dir.list();
for (int i = 0; i < subDir.length;i++)
{
   new File(dir, subDir[i]).delete();
}
}
sasikumar
  • 12,540
  • 3
  • 28
  • 48
0

Follow this link to listen to when your application is being uninstalled, and in the callback, delete the folder using @sasikumar's code below. Hope this helps.

Community
  • 1
  • 1
SimplyJaymin
  • 444
  • 8
  • 17