为什么Environment.getExternalStoragePublicDirectory在某些设备(自2011年初开始特别制造)中不起作用? [英] Why Environment.getExternalStoragePublicDirectory is not working in some devices(specially manufactured since early 2011)?
本文介绍了为什么Environment.getExternalStoragePublicDirectory在某些设备(自2011年初开始特别制造)中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将从相机捕获的图像存储到公共存储目录,这是我用于存储图像的代码的一部分:
I am trying to store the images captured from camera to public storage directory, here is my part of code for storing image:
protected File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
return image;
}
在大多数设备上都能正常工作,但在某些设备上我能得到
its working fine in most of the devices, but in some devices i get
java.io.IOException:打开失败:ENOENT(没有这样的文件或目录)
java.io.IOException: open failed: ENOENT (No such file or directory)
所以我的问题是,为什么相同的代码在大多数设备上都能正常工作,为什么在某些设备上不能正常工作,以及如何解决此问题?
So my question is why the same piece of code is working fine in most of the devices and why not in some devices and how to fix this issue?
推荐答案
请改用context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
.
这篇关于为什么Environment.getExternalStoragePublicDirectory在某些设备(自2011年初开始特别制造)中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文