With Android Q it's no more possible to file access, so how to call the method scanFile
of class MediaScannerConnection
without a path? Is there any alternative?
Asked
Active
Viewed 108 times
0

greywolf82
- 21,813
- 18
- 54
- 108
-
"Is there any alternative?" -- if you are using the `MediaStore` to create the content (e.g., `MediaStore.insert()`), it will be indexed automatically. If you are using the Storage Access Framework, it is the responsibility of the documents provider to ask the `MediaStore` to index the content, if that's relevant for the particular storage location that the user chose. – CommonsWare Aug 05 '19 at 13:52
-
Ok, so we are saying that it's no more useful to use this class and it can be deprecated. – greywolf82 Aug 05 '19 at 13:54
-
If you have a filesystem path, `MediaScannerConnection` may still be valid. Your "it's no more possible to file access" statement is not quite accurate, as you can still use `getExternalFilesDir()`, `getExternalCacheDir()`, `getExternalMediaDir()`, etc. – CommonsWare Aug 05 '19 at 13:58
-
Yes, you are right. However it makes no sense to use these methods because the paths are private to the app. The goal of MediaScanner is to share media content in a single place. I'm wondering indeed what happens if I try to scan a file in a private directory, I guess the user won't see anything. – greywolf82 Aug 05 '19 at 14:00