I'm writing an android application that takes some pictures and would like to save them all in a unique directory associated to my application.
This directory should be accessible from the standard Gallery, in such a way that the user can later (when application is not necessarily running) check the pictures that were taken.
My problem is that every different phone vendor, with a different android version, has different paths for gallery.As an example:
Environment.getExternalStorageDirectory() + Environment.DIRECTORY_PICTURES +"/myFolder"
will work on Samsung Galaxy Nexus
running android 4.1.1
, and on Asus Transformer Pad
running android 4.0.3
, but not on HTC Desire
running android 2.3.5
.
This will cause my application to crash when trying to save a new directory within the specified path, as stated below:
boolean success = false;
myFolder = new File( Environment.getExternalStorageDirectory() + Environment.DIRECTORY_PICTURES + "/myFolder" );
if( myFolder.exists() ){
//do nothing
}else{
success = dvaFolder.mkdir();
if( success ){
// Do something on success
/*
* folder has been created
*/
} else {
// Do something else on failure
/*
* folder creation failed
*/
throw new RuntimeException("File Error in writing new folder");
}
}
How can I write a directory that will be accessible in gallery for all different vendors and android versions?
NOTE:
Logcat isn't much useful, cause it just returns the run time Exception.