How to store the data in to the SD-card and to delete this stored data when the application is uninstalled in Android

H

For Guidance follow this link
http://developer.android.com/guide/topics/data/data-storage.html

store file in to the sdcard use this code


private File cacheDir;

if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),"/Android/data/YOUR PACKAGE_NAME/files/");
else
cacheDir=context.getCacheDir();
if(!cacheDir.exists())
cacheDir.mkdirs();
}

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”.

About the author

abhijit.kurlekar
By abhijit.kurlekar

Category