In order to save a picture on the SD card, I currently use the function File.createTempFile
:
File imageFile = File.createTempFile(imageFileName, MyApplication.JPEG_FILE_SUFFIX, MyApplication.getAlbumDir());
I actually also tried with the standard way:
File imageFile = new File(MyApplication.getAlbumDir(), imageFileName + MyApplication.JPEG_FILE_SUFFIX);
Both are working, but in my case the first one is better than the second one because the function createTempFile
adds a long random number at the end of the file name making it unique.
To give you an example, here is what I get with both methods:
With createTempFile: IMG_2013-06-18_-1961144729.jpg
With new File: IMG_2013-06-18_.jpg
Finally my question is, is it safe to keep using createTempFile
to save my pictures or do I have to use the standard way and add some code to generate a unique file name? Should it only be used for temporary files?
I reviewed the documentation about the function but I did not find anything about the possible consequences of using it instead of new File
.