不在 Fresco 中显示图像文件

Not Show Image File in Fresco

我在 android 上使用 Fresco 库,但我没有显示我的 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")));

每个设备都没有与 mnt/sdcard/ 相同的目录层次结构,它可能是 0/mnt/sdcard/ 和类似的,所以永远不要对这些值进行硬编码。

相反,如果您想访问 Download 文件夹,则使用 File getExternalStoragePublicDirectory (String type) 仅访问 public 目录 所以使用

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

注意:确保您拥有所需的权限以及