Fetch icon indicating copy to clipboard operation
Fetch copied to clipboard

MediaStore Uri not supported

Open jemshit opened this issue 4 years ago • 6 comments

Hi, i'm trying to use this library and it seems like a great work 👍

I want to download file to shared storage (Movies/myVideo.mp4). Currently Fetch supports file:///files/ and content://com.contentprovider.provider/ URIs.

  • file:///files/ this is for (app-private directories + getExternalStoragePublicDirectory)
  • content://com.contentprovider.provider/, i think this is for Files created by other apps + SAF (ask user file dir. location explicitly)

If app wants to create file on shared storage

When getting URI from MediaStore, it returns something like content://media/external/video/media/148 which does not work with Fetch. This line throws FileNotFoundException: No item at content://media/external/video/media/148

Starting from Android 11, only choices seem to be (to create file on shared storage)

  • Use MediaStore implicitly
  • Ask user to choose file location explicitly. (SAF)

Imho best way to deal with File/Uri:

  • Not using raw File
  • Not opening FileDescriptor unless necessary (e.g: reading size). You have to close it when done (here it is not closed)
  • Pass Uri till the end, then open InputStream/OutputStream using AssetFileDescriptor.AutoCloseOutputStream(contentResolver.openAssetFileDescriptor) (for file://, content://) or contentResolver.openOutputStream (for content://media/)

jemshit avatar Apr 13 '21 18:04 jemshit

Same issue am trying to update my apps to supports android 11, but facing this issue for android 10, and 11, any quick solution ???

husam47 avatar Apr 17 '21 02:04 husam47

How i converted Uri to OutputStream.

jemshit avatar Apr 26 '21 09:04 jemshit

@jemshit Hi, I have a same issue, would you please say that how did you solve this issue? I'll be thankful if you help me

saeedata avatar May 04 '21 15:05 saeedata

@saeedata either download using okhttp without this library. Or use fetch to download to app private directory first, then copy to shared storage and delete temp file.

jemshit avatar May 04 '21 15:05 jemshit

@jemshit yeah I thought about these answers. BTW, thank you so much bro.

saeedata avatar May 04 '21 15:05 saeedata

I could integrate this library with Media store and sdk 30 without changing the library, Actually there are two bugs in the library, the first is in requesting to get storage permission in android 30, and the other is in creating file in Mediastore because the library seems that supports uri, however by implementing these problems in my app, I could integrate it with sdk 30. I also want to say, as I checked and reviewed the library full code, I want to raise another bug that is: if you pause a downloading file and reinstall the app, the library doesn't check the file size if it's available in path, download from the beginning.

saeedata avatar Oct 31 '21 22:10 saeedata