I’m developping a sort of camera app, and I need it to save each picture in a particular folder on my android device:
picture 1 will go in Project/1/Image.jpg
picture 2 will go in Project/2/Image.jpg
and so forth…
Here is the method that saves the images:
private void SavePicture( byte[] imageData )
{
File path = new File( Environment.getExternalStoragePublicDirectory ( Environment.DIRECTORY_PICTURES ) + "/Project" );
boolean success = true;
if( !path.exists() )
{
success = path.mkdir();
}
if( success )
{
int iterator = 0;
do
{
++iterator;
path = new File( path + "/"+Integer.toString(iterator) );
}while( path.exists() );
success = path.mkdir();
}
if(!success)
{
Log.d("ACTIVITY", "failed at creating directory!");
}
String filename = "Image.jpg";
try
{
Uri uriTarget = Uri.fromFile( new File( path, filename ) );
OutputStream output = getContentResolver().openOutputStream( uriTarget );
output.write( imageData );
output.flush();
output.close();
}
catch( FileNotFoundException e )
{
Log.d( "ACTIVITY", "Save image failed due to FileNotFoundException: " + e );
}
catch( IOException e )
{
Log.d( "ACTIVITY", "Save image failed due to IOException: " + e );
}
}
In this code I start with a loop to find to which number I’m at so if I have folder 1,2,3,4 I will create folder 5.
My problem is the following: When it goes through that loop the do{…}while(path.exists()); finds each of the folder I previously created. But when I look in my gallery I can’t see any picture or folder. I’ve also looked from the file system of the computer into the android device but couldn’t find any folder.
My guess is that the folder are hidden (it’s only an assumption…)
Thanks
You should have set permission to write in the manifest: