0

I use the Fresco library on android, but I do not show any image that I have from my phone.

in Xml

<com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/imgFile"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:padding="5dp" />

First piece of code

imgFile.setImageURI(Uri.fromFile(new File("file:///mnt/sdcard/Download/file.jpg")));

The second piece of code

holder.imgFile.setImageURI(Uri.parse("mnt/sdcard/Download/file.jpg"));

The third piece of code

holder.imgFile.setImageURI(Uri.parse("file:///mnt/sdcard/Download/file.jpg"));

The fourth piece of code

imgFile.setImageURI(Uri.fromFile(new File("file:///mnt/sdcard/Download/file.jpg")));

1 Answers1

2

Every device does not have same directory hierarchy as mnt/sdcard/ , it could be 0/mnt/sdcard/ and similar so never hard code these values.

Instead if you want to access Download folder then use File getExternalStoragePublicDirectory (String type) to access public directories only so use

File path = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_DOWNLOADS);
imgFile.setImageURI(Uri.fromFile(new File(path, "file.jpg")));

Note : Make sure you have the required permissions as well as runtime permissions for android M and above

Pavneet_Singh
  • 36,884
  • 5
  • 53
  • 68