I think that folders to save files must not be set to
Environment.getExternalStorageDirectory().
If we remove the SD card of a device this path can be unavailable...
I think the subpath must calculate each time with something like :
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
Log.v(TAG, "External storage available");
path = context.getExternalFilesDir(null);
}
if (path == null) {
Log.w(TAG, "External storage unavailable - using local memory");
path = context.getFilesDir();
}
Attention to the calculation of the remaining space.