Fetch
Fetch copied to clipboard
MediaStore Uri not supported
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
< API 29, they have to usegetExternalStoragePublicDirectory>= API 29they need to use MediaStore
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
MediaStoreimplicitly - Ask user to choose file location explicitly. (SAF)
Imho best way to deal with File/Uri:
- Not using raw
File - Not opening
FileDescriptorunless necessary (e.g: reading size). You have to close it when done (here it is not closed) - Pass
Uritill the end, then openInputStream/OutputStreamusingAssetFileDescriptor.AutoCloseOutputStream(contentResolver.openAssetFileDescriptor)(forfile://,content://) orcontentResolver.openOutputStream(forcontent://media/)
Same issue am trying to update my apps to supports android 11, but facing this issue for android 10, and 11, any quick solution ???
How i converted Uri to OutputStream.
@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 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 yeah I thought about these answers. BTW, thank you so much bro.
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.