我正在尝试根据说明here将图像写入文件。但是,我得到了这个例外:
libcore.io.ErrnoException: open failed: EACCES (Permission denied)
这是我的代码,这个异常显然会弹出:
private File createImageFile(int side) throws IOException {
String timestamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "";
if (side==1) {
imageFileName = "Front_"+timestamp;
} else {
imageFileName = "Side_"+timestamp;
}
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName,
".jpg",
storageDir
);
// Save the file
mCurrentPhotoPath = "file:"+image.getAbsolutePath();
return image;
}
感谢您的帮助。
答案 0 :(得分:0)
问题在于它应该是
File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
而不是File storageDir = this.getExternalFilesDir(null);
{{1}}