Anyone familiar with the new scoped storage rules?...
# android
t
Anyone familiar with the new scoped storage rules? https://developer.android.com/training/data-storage/shared/media#remove-item I’m attempting to delete a file like so:
Copy code
context.contentResolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, "${MediaStore.Audio.Media._ID} = ?", arrayOf(id.toString()))
Supposedly, if I don’t have permission, this should throw a
RecoverableSecurityException
on Android Q, and I should be able to use an IntentSender to have the user grant permission. Instead, I just get a result of
0
from the
delete()
call, meaning no files were deleted. Any ideas?
t
I have had the exact same problem a few months ago. This only works if you specify the full Uri of the Media you'd like to delete, the one obtainable with
ContentUris.withAppendedId(Media.EXTERNAL_CONTENT_URI, longId)
. For more information see my question an its excellent answer on SO: https://stackoverflow.com/questions/58283850/scoped-storage-how-to-delete-multiple-audio-files-via-mediastore
t
Thanks 🙂 I did come across this answer. I didn’t understand what
audioContentUri
was for a while, but I did get it wokring. Turns out the underlying file isn’t deleted even when contentResolver.delete() returns >= 1
t
Looks like Scoped Storage feature isn't really ready on Android Q ... I recommend sticking with
requestLegacyExternalStorage="true"
until at least Android 11 (but that flag is still allowed on Android 11 !)