I currently use Environment.getExternalStorageDirectory() to obtain a location where I can store some data temporarily and then after being used gets deleted. This data can range from 1-100MB.
This works fine but on some cases the state of the external storage is removed or unmounted etc… and I can’t access to store my data…
My question is what could be a good fallback solution when this storage is not available?
I’m targeting Android 1.6 and greater.
Note that you should not use the path returned by
Environment.getExternalStorageDirectory()directly:Use the path returned by
getFilesDir()to store files private to your app on the internal storage, orgetExternalFilesDir()to store on the external storage.If you’re storing data temporarily, consider using the cache directories.
Use the methods:
getCacheDir()orgetExternalCacheDir()on the external filesystem. Read the documentation for important differences between them.If the size of the data to be stored is not large, you’d be better off using the internal storage. Otherwise, you’ll have to managing the complexity of detecting if external storage is available, falling backing to internal storage if not.