代码似乎工作正常。问题是,之后在我的画廊中,我没有带有我的照片的文件夹“myFolder”。相反,图片会保存到storage/sdcard0/DCIM/camera
并且myFolder
不会显示。
myDirectory = final static String myDirectory = "myFolder"
。
private void createDirectoryAndSaveFile(Bitmap imageToSave, String fileName) {
final File imageRoot = new File(Environment.getExternalStorageDirectory(), myDirectory);
if (!imageRoot.exists()) {
imageRoot.mkdirs();
}
File file = new File(imageRoot, fileName);
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream out = new FileOutputStream(file);
imageToSave.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}