我试图保存由相机意图拍摄的图像。我的代码没有工作,所以当我添加检查是否创建了目录时,它应该没有。可能是什么问题?我在模拟器上试试。
01-11 13:50:28.946: D/file(1161): file is /mnt/sdcard/M3
01-11 13:50:28.946: D/file(1161): photo is /mnt/sdcard/M3/3_1.jpg
我在日志中得到了上述内容。
下面是我在打开相机的按钮上的代码
File sdCard = Environment.getExternalStorageDirectory();
File file = new File (sdCard.getAbsolutePath() , File.separator + "/M3");
file.mkdirs();
String name = e_id + "_" + (size+1)+ ".jpg";
File newfile = new File(file,name);
newfile.mkdir();
Log.d("file"," file is " + file.toString());
Log.d("file"," photo is " + newfile.toString());
if(!file.mkdir())
{
Log.d("file"," not created ");
}
if(!newfile.mkdir())
{
Log.d("newfile"," not created ");
}
else
{
outputFileUri = Uri.fromFile(newfile);
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(intent, TAKE_PICTURE);
}