Shubhank Gupta
Shubhank Gupta

Reputation: 863

FileNotFoundException while showing the image from the local storage

I am trying to show the image from my download folder for that i am using this.

    Bitmap bmImg = BitmapFactory.decodeFile("file:/storage/sdcard0/download/13448FILE.jpg");
    message_image.setImageBitmap(bmImg);

but while doing that i getting the exception i already check this path the image is located there.I already given the WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permission in manifest

Log cat

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /file:/storage/sdcard0/13448FILE.jpg: open failed: ENOENT (No such file or directory)

Upvotes: 1

Views: 1025

Answers (2)

Lucas
Lucas

Reputation: 441

uses this for get default path:

Bitmap bmImg = BitmapFactory.decodeFile(Environment.getExternalStorageDirectory() + "/download/13448FILE.jpg");

Upvotes: 1

CommonsWare
CommonsWare

Reputation: 1006674

First, decodeFile() does not use a scheme. You would need to remove file:.

Second, do not harcode paths, outside of lightweight testing. Your path is wrong on many Android devices.

Third, do not decode images on the main application thread, as you appear to be doing here. There are many image loading libraries for Android that can safely decode the image on a background thread, loading it into your ImageView when it is ready.

Upvotes: 4

Related Questions