Skip to content
Advertisement

Android ENOENT with some files

I use a Intent to get pictures path and open them into a File. I can open files allocated in “Camera” folder like “/storage/emulated/0/DCIM/Camera/IMG_20160817_232858.jpg”, but I cannot open files in locations like “/storage/emulated/0/Pictures/1634894_.png”. Using file.exists() it just says that it doesn’t. Need to say that I’m using API 23 and I request READ_EXTERNAL_STORAGE, so this souldn`t be a problem… But I can’t access those files even with that. What can be wrong?

JavaScript

Updated: it doesn’t happens with all the files from the same folder, just some of them, but they really exist since I can open them from the gallery.

Update2: I use this Intent.

JavaScript

Update3: Running time permissions:

JavaScript

Permissions in Manifest:

JavaScript

Advertisement

Answer

The MediaStore will index images that are not accessible to you from the filesystem. There is no requirement for a DATA column to return a value that you can use.

Instead, stop trying to get a File, and use the Uri itself:

  • getContentResolver().openInputStream() to get an InputStream on it
  • DocumentFile.fromSingleUri() to get a DocumentFile for easy access to metadata (e.g., MIME type)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement