My application uses quite a lot of pictures that are downloaded from the internet and cached locally on the Android phone. I am wondering, what is the correct way to save those pictures. There are several ways I see, that are not fully satisfying.
Save them on SD Card in a public folder
Save them on SD Card in a non-public folder
Save them inside the application
What is the correct way of locally saving the images of my application to not distract the user and leave no garbage anywhere?
Touch and hold the image. Select a save option (e.g., Save attachment, Save to SD card, etc.). Unless otherwise specified, the image is saved to the default picture/video location (e.g., Gallery, Photos, etc.).
The photos you taken on phone camera will be saved under dcim folder in the internal storage or filemanager in android mobiles,so if you want to open gallery photos in file manager then click on DCIM folder and then click on camera to view taken photos and videos of your mobile.
One of the best of these options is Google Photos. Google's free app allows anyone to upload their photos and videos to the cloud. Even better, it comes with free unlimited storage for videos (up to 1080p) and photos (up to 16-megapixels).
Your best solution is to use:
context.getCacheDir()
This directory is private to the application and will be deleted on uninstall, furthermore the system can delete from this directory for you if the device is running short of space.
Note though that the docs say:
you should not rely on the system deleting these files for you; you should always have a reasonable maximum, such as 1 MB, for the amount of space you consume with cache files, and prune those files when exceeding that space
If you need a lot of space and would rather use the SD card you can call
getExternalCacheDir()
instead. These will also get removed on uninstall, but the system does not monitor the space available in external storage, so won't automatically delete these files if low on space. If using this option you should also check that external storage is available with
Environment.getExternalStorageState()
before attempting to write to it.
You can hide images from the MediaScanner if you put it in a hidden dir (i.e., with a dot prefixed) such as /sdcard/.donotscan/
.
Update: As romainguy mentions on twitter this also works if you put a file named .nomedia
into the dir.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With