Monday, April 23, 2012

Android: Saving cache files on external storage.

Hi,

If you want to save some files on external storage and you want those files to be removed on application un-installation, then do as the documentation says ;)

If you're using API Level 8 or greater, use getExternalCacheDir() to open a File 
that represents the external storage directory where you should save cache files. If 
the user uninstalls your application, these files will be automatically deleted. However,
 during the life of your application, you should manage these cache files and remove 
those that aren't needed in order to preserve file space.  
   
If you're using API Level 7 or lower, use getExternalStorageDirectory() to open a File
that represents the root of the external storage, then write your cache data in the following
 directory:  
   
 /Android/data/<package_name>/cache/ 
 The <package_name> is your Java-style package name, such as "com.example.android.app".  

Unfortunately, our apps can not receive un-install intent. So, this is the best way to do that.

That's it, don't hesitate to comment, to share your knowledge and to correct me.

0 comments:

Post a Comment