MediaStore and ContentRepository < Android 10from the CommonsWare Community archives
At September 7, 2021, 12:47pm, Jan asked:
I’ve read both Q and R books regarding MediaStore but can’t figure something out.
On Android 10 and 11, MediaStore and ContentResolver.insert work fine. My media is stored and 3rd parties like Youtube Music will show
my songs on my device. The location from ContentResolver is
content://media/external/audio/media/35 where 35 is the ID
On Android < 10, I can’t get them to show in the right place for 3rd parties.
When MediaScannConnection scanFile completes successfully, it gives me a uri of:
The contentResolver.update call using this uri is successful. But third parties don’t read this location and show my device’s library of songs.
I query MediaStore using MediaStore.Audio.Media.EXTERNAL_CONTENT_URI and the entry that was just successfully made and updated in MediaStore does not show in the results.
I am using context.getExternalFilesDir because the old way of using
is now deprecated.
How do I make my media show in the proper place in MediaStore for access by 3rd party apps?
At September 7, 2021, 2:27pm, mmurphy replied:
I am uncertain what you are doing with
Yes, but you can still use
Environment.getExternalStoragePublicDirectory() for Android 9 and older.
I have not attempted to store music content on an Android device, let alone in recent years. My initial attempt would be to use
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) on Android 9 and older devices and to use
MediaStore directly on Android 10+.
At September 7, 2021, 2:52pm, Jan replied:
I call update on the resolver after the successful scan to update the display name. Otherwise it’ll remain null.
I tried the getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC) and it was the same as using context.getExternalFilesDir(Environment.DIRECTORY_MUSIC) (and added the requestLegacyExternalStorage=“true” to the manifest).
Doesn’t sound like there is a way to do this when you set the target sdk to 30 (like you are required in November, 2021)
At September 7, 2021, 3:34pm, mmurphy replied:
That is odd. I would have expected it to be the filename.
I suspect strongly that there is a solution. You might scan through music-related open source projects, see which ones relate to downloading music or managing local music, and see what they do.