tonyofrancis / Fetch

The best file downloader library for Android
https://www.meta.stackoverflow.com/tags/fetch2
Apache License 2.0
1.66k stars 343 forks source link

Some files (Created by SAF uri) not updated in Android MediaStore #476

Closed jpvs0101 closed 4 years ago

jpvs0101 commented 4 years ago

I use SAF in fetch. Sometimes newly downloaded files not updated in Android MediaStore. So other apps can't detect the file. (Device: Redmi Note 7s, MIUI 11, Android 9)

Example: Download several mp3 files using fetch. One or two files not showing in Music Player.

captain-nemo1 commented 4 years ago

Maybe MediaStore doesn't get updated. Sometimes this happens. I had this problem earlier in my app. I used MediaScannerConnection(context,String[]{path), mimeType, callback) after download finishes. This will update MediaStore.

jpvs0101 commented 4 years ago

Maybe MediaStore doesn't get updated. Sometimes this happens. I had this problem earlier in my app. I used MediaScannerConnection(context,String[]{path), mimeType, callback) after download finishes. This will update MediaStore.

What is exactly path means? uri.toString() or uri.getPath()? Because it seems like MediaScannerConnection() doesn't mind uris....

captain-nemo1 commented 4 years ago

Path means the directory you want to scan. You can read about it more in the Android Documentation. For example, if you want to scan the Storage just pass Environment.ExternalStorageDirectory().

jpvs0101 commented 4 years ago

Path means the directory you want to scan. You can read about it more in the Android Documentation. For example, if you want to scan the Storage just pass Environment.ExternalStorageDirectory().

Scanning entire folder might take more battery. So scanning individual file is better. Also it is better if it is inbuilt in Fetch!

tonyofrancis commented 4 years ago

@jpvs0101 Fetch's main purpose and goal is to be the best file downloader on Android, not media organizer. I'd recommend after getting a file status of completed your code calls the necessary APIs on MediaStore to make sure media files are synced properly.

jpvs0101 commented 4 years ago

I understand. Fetch saves file. Just one extra step needed for special cases like SAF. Otherwise it's purpose not fulfilled. Because saving files without access (partially) is not usually most developers expect. Atleast provide an option. It will be really helpful.

Pie - MIUI 11 (Redmi Note 7s) Issue happens when I Choose 'Download' (Default option SAF document chooser UI) as location. If I choose other folders, seems like works normal.