I am trying to save images taken from the camera to the shared storage directory, here is my piece of code for saving the 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; }
works on all devices, but on some devices I get
java.io.IOException: open failed: ENOENT (There is no such file or directory)
So my question is why the same piece of code works fine on most devices and why not on some devices and how to solve this problem?
Use context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)instead.
context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
, , , . : " , , , ?" ( ), Context.getExternalMediaDirs(). API 19 , !
Context.getExternalMediaDirs()
" " (O_o), Environment.getExternalStorageDirectory() Environment.getExternalStoragePublicDirectory(String). . , , , . API , paths.mkdirs() , .
Environment.getExternalStorageDirectory()
Environment.getExternalStoragePublicDirectory(String)
paths.mkdirs()
File storageDir = new File(PATH_TO_PICTURES)
File storageDir =new File(PATH_TO_PICURES_EXTERNAL)
, , :
if(storageDir.isDirectory())