私は一種のカメラアプリを開発しています.Androidデバイスの特定のフォルダーに各写真を保存する必要があります:
画像 1 は Project/1/Image.jpg に入ります
画像 2 は Project/2/Image.jpg に入ります
などなど…
画像を保存する方法は次のとおりです。
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 );
}
}
このコードでは、現在の番号を見つけるためのループから開始するので、フォルダー 1、2、3、4 がある場合はフォルダー 5 を作成します。
私の問題は次のとおりです。そのループを通過すると、do {...} while(path.exists()); 以前に作成した各フォルダーを検索します。しかし、自分のギャラリーを見ると、写真やフォルダーが表示されません。また、コンピューターのファイル システムから Android デバイスを調べましたが、フォルダーが見つかりませんでした。
私の推測では、フォルダーは非表示になっています (これは単なる仮定です...)
ありがとう