Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete the data written on sd card automatically on uninstalling the android app?

I have developed an android application which writes to device's sd card. I want that as soon as I uninstall the app the data written on sd card should be removed automatically . Is there a way to do this ??? I am using android 2.1 . Thanks for the help in advance .

like image 412
techayu Avatar asked Oct 08 '22 14:10

techayu


2 Answers

its from the android documentation: http://developer.android.com/guide/topics/data/data-storage.html#ExternalCache

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//cache/ The is your Java-style package name, such as "com.example.android.app".

like image 142
Vikram Avatar answered Oct 12 '22 02:10

Vikram


If you put your data inside android/data/your.package.name it will automatically get deleted. Both on SD and on local.

like image 22
Warpzit Avatar answered Oct 12 '22 03:10

Warpzit