Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to delete files from SD card after uninstall my application

Tags:

android

I am working on application which will create some text files into the SD card and store some data into it.

These files will be there in the SD card all the time.

Whenever user uninstall my application , I want to delete all the files in SD card which has been created by my application.

I can't clean up in onDestroy() as it will be called many times in application life cycle.

Please suggest me what I have to do to make sure my files will be get deleted without any user interaction.

I got to know that getExternalCacheDir() will do the what I need , But my files are big , I need 1GB of space from the SD card , can getExternalCacheDir() useful for me.?

like image 533
brig Avatar asked Dec 05 '25 01:12

brig


1 Answers

You should be using Context.getExternalFilesDir(), from the API reference:

"This is like getFilesDir() in that these files will be deleted when the application is uninstalled"

like image 72
K-ballo Avatar answered Dec 07 '25 15:12

K-ballo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!