Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - delete files on SD card on uninstall

My app downloads some multi-media files from a server when it's installed. I do this to save space on the size of the app. However, the drawback of this approach is that when the app is uninstalled, it doesn't delete those files. I've seen reports that this is possible, but I can't seem to make it work. Is there a way to do this on uninstall, or should I just forget about it?

Note that I have the app installed on the SD card by default as well, but I'm not sure if all phones will automatically support this.

like image 411
Jack BeNimble Avatar asked Jul 04 '11 17:07

Jack BeNimble


2 Answers

from http://developer.android.com/guide/topics/data/data-storage.html#filesExternal "If you're using API Level 7 or lower, use getExternalStorageDirectory(), to open a File representing the root of the external storage. You should then write your data in the following directory:

/Android/data/<package_name>/files/

The <package_name> is your Java-style package name, such as "com.example.android.app". If the user's device is running API Level 8 or greater and they uninstall your application, this directory and all its contents will be deleted."

like image 153
constantine Avatar answered Nov 09 '22 02:11

constantine


Could you download the files and write them to the apps internal space using the methods explained here : Internal Storage

Files written to the internal storage are automatically removed when the user uninstalls your application.

From what I've read Android does not allow you to modify the uninstall process to help protect against malware.

Starting with Android 2.2 (API level 8) apps can be installed on the sdcard.

See here for more info : Installing to application to sd card

Edit : apparently there is also an external cache that you can use that, according to the doc gets removed when the user uninstalls your app also : External cache

like image 42
Brandon Haugen Avatar answered Nov 09 '22 02:11

Brandon Haugen