BitmapFactory open failed: ENOENT (No such file or directory)

6.4k views Asked by At

I am trying to Take a Photo with Android Camera Intent as shown in this Tutorial: http://developer.android.com/training/camera/photobasics.html#TaskScalePhoto

The Photo is perfectly taken and is also safed at the given path. But anyway i'm getting following Error:

06-25 14:46:02.228 9070-9070/de.ema.flo.grapp E/BitmapFactory﹕ Unable to decode stream: java.io.FileNotFoundException: file:/storage/emulated/0/Android/data/de.ema.flo.grapp/files/Pictures/IMG_20150625_144559002.JPG: open failed: ENOENT (No such file or directory)

Create Image:

private File createImageFile() throws IOException {
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmssSSS").format(new Date());
    File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = new File(storageDir, "IMG_" + timeStamp + ".JPG");
    mCurrentPhotoPath = "file:" + image.getAbsolutePath();
    return image;
}

Following code is called after taking the Photo in the Intent

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == ACTION_TAKE_PHOTO_B && resultCode == Activity.RESULT_OK) {
        if (mCurrentPhotoPath != null) {
            ImageView mImageView = (ImageView) getActivity().findViewById(R.id.grillplatz_erstellen_image);

            Bitmap bitmap = BitmapFactory.decodeFile(mCurrentPhotoPath);

            // Associate the Bitmap to the ImageView
            mImageView.setImageBitmap(bitmap);
            mCurrentPhotoPath = null;
        }
    }
}

I also tried it with this instead. But the result was the same: FileNotFoundException...

try {
    InputStream is = new FileInputStream(file);
    Bitmap bitmap = BitmapFactory.decodeStream(is);
} catch (FileNotFoundException e) {
    e.printStacktrace();
}

Are there any problems with this code? What could I try to change?

1

There are 1 answers

1
Vatsal Shah On

Please check the updated code.

    private File createImageFile() throws IOException {
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmssSSS").format(new Date());
        File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES);
if(!storageDir.isexist)
storageDir.mkdirs();
        File image = new File(storageDir, "IMG_" + timeStamp + ".JPG");
        mCurrentPhotoPath = "file:" + image.getAbsolutePath();
        return image;
    }

Let me know if it will help you or not.