Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 232
Nik Avatar asked Mar 01 '12 09:03

Nik


2 Answers

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.

like image 145
Thommy Avatar answered Nov 13 '22 09:11

Thommy


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();
like image 42
Maneesh Avatar answered Nov 13 '22 09:11

Maneesh