1

I am trying to put an image in an imageView by code. I have some images in the Drawable directory but, with other images, I have to use the internal storage. In first case,

holder.picture.setImageDrawable(getResources().getDrawable(R.drawable.my_image));

works but, in the second case, Android give me this error:

BitmapFactory: Unable to decode stream: java.io.FileNotFoundException:  /storage/emulated/0/Sensia_Sniffer/18_04_2018/18_56_18_photo.JPEG (No such file or directory)

and I don't know why. I am using this lines:

Drawable drawable = Drawable.createFromPath(my_image_path);
holder.picture.setImageDrawable(drawable);

and in AndroidManifest.xml I have this permissions:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Could you help me with this?

Thank you very much!!!

  • `/storage/emulated/0/Sensia_Sniffer/18_04_2018/18_56_18_photo.JPEG` is an external storage path not internal storage. – Ghulam Moinul Quadir May 08 '18 at 15:06
  • Share your code of creating file path. – Ghulam Moinul Quadir May 08 '18 at 15:07
  • can you share your code? – Zobair Alam May 08 '18 at 15:19
  • Yes sorry, this is external storage but, this is the path that I want to load. The path is correct – Iván de la Cruz May 08 '18 at 15:21
  • Use an image-loading library, such as Glide or Picasso, so the actual image-loading logic can be performed on a background thread. – CommonsWare May 08 '18 at 15:34
  • am trying to use a File to put it in a imageView. I have a problem with it because, the path is correct, but the file created doesn't exist. This is my declaration code: File file = new File(mPlacePictures[position % mPlacePictures.length]); if (file.exists()) holder.picture.setImageURI(Uri.fromFile(file)); else System.out.println("Error. No such file."); Path that I want to load: /storage/emulated/0/Sensia_Sniffer/19_04_2018/09_55_10_photo.JPEG This image checks the path is correct: Image path Which could be the problem? Thank you very much!! – Iván de la Cruz May 09 '18 at 08:15
  • https://stackoverflow.com/a/29163806/9025311 –  May 09 '18 at 08:26

1 Answers1

0

You forgot to ask for runtime permissions for the requested permissions in manifest file.

Needed for Android 6+.

greenapps
  • 11,154
  • 2
  • 16
  • 19