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: 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?